I am trying to read a text file which contains the data for several matrices and load them in different matrices in matlab. An example of my text file looks like this:
19.623 -15.67 42.995
17.942 -10.923 47.112
23.806 -14.332 49.912
21.582 -11.218 46.203
18.031 -12.567 44.381
15.931 -18.897 39.046
18.497 -17.457 44.32717.548 -18.604 44.24
15.931 -18.897 39.046
18.43 -16.582 43.091
18.497 -17.457 44.327
16.695 -17.627 39.364
17.548 -18.604 44.2420.436 -16.416 44.281
17.984 -16.918 44.441
14.703 -17.17 40.697
17.078 -18.111 44.22
16.322 -16.342 38.961
19.582 -18.281 39.937
14.941 -16.27 39.53
18.43 -16.582 43.091
This file represents three matrices where the first, second and third matrices dimensions are 7×3, 6×3 and 8×3 respectively. The matrices are separated using a new line. I have tried using S = LOAD(FILENAME) command but this command creates a 21×3 matrices which is concatenation of all the rows. How can I define a matrix separator (delimiter) for my matrices so it produces different matrices based on different segment of my file? Note that the number of all columns is always 3.
Thanks a million for all your help. I really appreciate it.
If you do not have NaN values in your data, you can use
textscanwith a\ndelimiter. It produces NaN values when a blank line is read. Not very elegant but it does the trick. I am sure there are plenty of other ways of doing this.I must add that if you have any control over how these data files are created you should probably think of changing their format to either one matrix per file or a Matlab mat file.