Friday, May 22, 2009

[SW] Scilab -- reading a data file

To read data files we have generated by other means into Scilab, use ``read'' seems a convenient way.

Don't use ``load'', which looks like a function to load variables saved by Scilab using ``save'' that produces binary data files.

Take one of my data files as example, the data file consists of four columns: time, ax, ay, and az1

1.00000 0.139641 -0.139664 0.980796
1.03125 0.125245 -0.152101 0.975367
1.06250 0.143240 -0.153878 0.966317
1.09375 0.141441 -0.157431 0.964507
1.12500 0.127045 -0.139664 0.964507
1.15625 0.134243 -0.157431 0.968127
1.18750 0.137842 -0.148548 0.982606
1.21875 0.128844 -0.148548 0.975367
1.25000 0.127045 -0.144994 0.984416
1.28125 0.146839 -0.153878 0.971747
1.31250 0.150438 -0.148548 0.966317
.
.
.

Then use ``read'' to get the overall data as a matrix.

data = read('dataFileName',-1,4); // -1 means we don't know the data number of row
data_time = data(:,1); // assign the 1st column to the 1st variable
data_accx = data(:,2); // assign the 2nd column to the 2nd variable
data_accy = data(:,3);
data_accz = data(:,4);

For the convenience of future using or modification, we can save the above script as the fooFileName.sce file. Next time when we need the script, just use ``chdir'' to change the working directory where the sce file exists, then use ``exec fooFileName.sce'' to execute the script.

No comments:

Post a Comment