[Scilab-users] Reading a matrix - variable number of lines, columns

SCHULZ Wolfgang W.Schulz at ove.at
Wed Aug 21 15:00:03 CEST 2013


Hello,
I have a file with different matrices inside. This matrices have a line with a certain keyword before the data.
I can read the data with the following code if I have nlat rows and 5 columns.

fid=mopen(datafile,'r');                                   // open the file for reading
    //Skip data till the data part:
    line=mgetl(fid,1);
    while(strcmp(line, " Avg Num Sensors: ")~=0)
        line=mgetl(fid,1);  
    end
    //Read the data
    ANSR=mfscanf(nlat,fid,'%f %f %f %f %f ');
mclose(fid);

My problem is the following: I searched but I didn't find a way to make the number of columns a variable.
I tried to read the data line by line  and wanted to use msscanf to scan the string but that didn't work.
In the following example I tried to analyze 5 values of the string line but it didn't work.
-->line
 line  =
 
        0.0        2.8        5.7        4.2        3.5 
a= msscanf(5,line,'%f')

Thanks for your help
Wolfgang


Example data file:
    Stroke Count: 
         0         77        246      24937          8 
         0       5862       7895        318        300 
      2387      15871       1151       3166       2057 
      5099       1721          1         27         80 

Median Semimajor: 
       0.0 >=     0.9        0.3        0.5 >=     0.9 
       0.0        0.1        0.2 >=     0.9 >=     0.9 
       0.4        0.2        0.3 >=     0.9 >=     0.9 
       0.2 >=     0.9        0.1 >=     0.9 >=     0.9 

 Avg Num Sensors: 
       0.0        2.8        5.7        4.2        3.5 
       0.0        7.9        6.6        5.0        5.7 
       4.5        6.7        6.5        6.3        7.3 
       7.4        5.1        2.0        5.0        5.8



More information about the users mailing list