Reading and analyzing a text file in octave / matlab

I am trying to read some values ​​from a file in an octave program (I suspect matlab is similar), but not sure how to do this.

I have an input file of the form:

xy ABC a_11 ... a_1n a_21 .. a_2n ... a_m1 ... a_mn 

Where x, y are twins, A, B, C are integers, a_11 ... a_mn is a matrix.

I have seen examples of how to read only in the matrix, but how can I read such mixed things?

+6
source share
1 answer

In my opinion, this is not a good way to store data. But the octave offers functionality to read this also 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 your data as follows:

 integers = dlmread('test.csv', '', [0 0 0 1]); floats = dlmread('test.csv', '', [1 0 1 3]); matrix = dlmread('test.csv', '', 2, 0); 
+8
source

Source: https://habr.com/ru/post/902174/


All Articles