How can I read or load a .txt with multiple vector/matrix in it?
1 view (last 30 days)
Show older comments
Hello,
I am a beginner in Matlab, so if my question is very obvious please excuse me.
I want to read a .txt file with multiple vectors and matrices in it. These vectors/matrices are also from a different size. The size of these vectors/matrices is known in front.
I already tried the function load and textread, but is gives an error.
For example, the txt file: With first matrix is 1x1 second matrix is 2x10 third matrix is 10x1 etc.
Thanks for your help!
10
20355.966023 16167.127237
39988.592020 19773.197847
23572.548971 31529.184022
37304.369590 32079.249435
24512.513179 38835.826089
40867.253869 38565.884488
27520.840478 46921.515986
36067.877874 44894.490748
19345.710923 51972.040940
33635.749233 49663.479404
75.455160 36.992250 54.503740 19.269930 20.093530 17.650830 56.770230 17.080500 18.831190 16.385700
0 Comments
Accepted Answer
Massimo Zanetti
on 27 Sep 2016
Edited: Massimo Zanetti
on 27 Sep 2016
Use the function dlmread by changing its parameters to access the txt file at different line and column offsets. For the text file example you posted:
M1 = dlmread('file.txt',' ',[0 0 0 0]); %the 1x1 matrix
M2 = dlmread('file.txt',' ',[1 0 10 1]); %the 10x2 matrix
M3 = dlmread('file.txt',' ',[11 0 11 9]); %the 1x10 vector
0 Comments
More Answers (1)
See Also
Categories
Find more on Text Files in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!