[scilab-Users] Help in reading txt file: how to skip the title

harishankar ramachandran hsr at ee.iitm.ac.in
Thu May 7 06:26:59 CEST 2009


The following program does the specific job:

// to read in a data file containing header lines starting with
// "*" and to read in the columns after the last header line.
A=read("data.txt",-1,1,"(a)"); // read in the file
jj=grep(A,"*"); // find lines containing "*"

// We want to skip upto all lines containing "*" So start after
// the last such line
ibeg=jj(length(jj))+1;
iend=size(A,"r");
m=iend-ibeg+1;
[n,v1,v2,v3]=msscanf(m,A(ibeg:iend),"%f %f %f");

clf
subplot(3,1,1);
plot2d(1:m,v1');
subplot(3,1,2);
plot2d(1:m,v2');
subplot(3,1,3);
plot2d(1:m,v3');

// Note that this script hardcoded the number of columns and does
// no error checking. Since column information is present in the
// file, one could also extract that info and construct the 
// format string appropriately. Or use the logic in fscanfMat to directly
// figure out the number of columns.

Not sure this is quite what you wanted.

regards

hari ramachandran

On Wednesday 06 May 2009 21:49, Zhiming Qi wrote:
> *****************************
> * Subplot Definitions *
> *****************************
> 1
> *****************************
> * COLUMN LABELS *
> *****************************
> DAY
> DEPTH (CM)
> SOIL WATER CONTENT (VOL)
> ****************** DATA STARTS HERE *****************
> 274 1.000 0.2898
> 274 2.000 0.2919
> 274 4.000 0.2939
> 274 7.000 0.2990
> 274 10.00 0.3035
> 274 13.00 0.3130
> 274 16.00 0.3172
> 274 20.00 0.3201
> 274 24.00 0.3243
> 274 27.00 0.3272
> 274 30.00 0.3300
> 274 33.00 0.3210
> 274 36.00 0.3223
> 274 40.00 0.3236
> 274 44.00 0.3258
> 274 48.00 0.3273
> 274 53.00 0.3302
> 274 57.00 0.3345
> 274 60.00 0.3381
> 274 63.00 0.3331

-- 
Dr. Hari Ramachandran, Professor, 332B ESB, EE Dept, IIT-Madras
Interests: Nonlinear Optics, Nonlinear Waves, Plasma Physics, Particle 
           Simulations, Computational Algorithms, Linux.
Off: 91-44-2257-4421                    Fax: 91-44-2257-0120
Res: 91-44-2663-1863             Home Email: omkarbharathi at gmail.com



More information about the users mailing list