Loading data which is a triangular array.
2 views (last 30 days)
Show older comments
Hello.
I have a data file which consists of a triangle of numbers and I would like to be able to manipulate the file in Matlab, but since it is not a matrix I cannot get the file to load.
I am happy to 'embed' the data in a square matrix (with 0s in the previously empty places), but I do not want to edit the data file itself (thousands of rows), so would have to append these 0s through Matlab itself. Is there a simple solution for getting the data into a matrix? Or another way of accessing the data?
Thank you.
1 Comment
Teja Muppirala
on 5 Apr 2011
Is this a plain text file? Binary? Some special format?
When you say it consists of a triangle of numbers, does it look like this:
1
1 1
1 2 1
1 3 3 1
Or something else?
It's hard to answer this question without this sort of information.
Answers (1)
the cyclist
on 5 Apr 2011
One method you may be able to use is to first load into a cell array, then convert the cell array into a numeric one.
Also, different command are better than others for reading certain types of data from files. I have found the "readtext" command from the file exchange to be very robust:
This is not to be confused with the "textread" command.
0 Comments
See Also
Categories
Find more on Data Type Conversion 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!