I am trying to read in some values from a file in an octave program (I suspect matlab is similar), but not sure how to do it.
I have input file in the form:
x y
A B C
a_11 ... a_1n
a_21 .. a_2n
...
a_m1 ... a_mn
Where x,y are doubles, A, B, C are integers, and a_11...a_mn is a matrix.
I saw examples of how to read in just the matrix, but how can I read mixed stuff like this?
In my opinion this is not a good way of storing data. But octave offers the functionality to read this as well with dlmread:
data = dlmread (file, sep, r0, c0)
data = dlmread (file, sep, range)
If you have this text file test.csv:
1 2
1.1 2.2 3.3 4.4
1 2 3
4 5 6
7 8 9
You can read in your data like this:
integers = dlmread('test.csv', '', [0 0 0 1]);
floats = dlmread('test.csv', '', [1 0 1 3]);
matrix = dlmread('test.csv', '', 2, 0);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With