octave - Reading a Float Line from a File W/o Knowing Its Length -


i relatively new octave, question is: how can read each line containing numbers file without knowing length?

line lengths vary.

i know how many lines there are.

each line has 2 or more float values, can't use "fgetl" because mean string, need array.

there many options , depends hoe want have data stored. 1 way:

yourfile:

3.14 5.2 6.4 1.2 8.4 9.2 10.5 12.4 

the code

fid = fopen ("yourfile", "r"); while ((tmp = fgetl (fid)) != -1)   c = strread (tmp, "%f")   #process c here endwhile fclose (fid); 

gives:

c =     3.1400    5.2000    6.4000  c =     1.2000    8.4000  c =  9.2000 c =     10.500    12.400 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -