Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to read .csv file in Scilab.

852 views
Skip to first unread message

qingx...@gmail.com

unread,
Aug 6, 2007, 8:02:18 PM8/6/07
to
Hi,
I'm learning Scilab now, I wonder how to read .csv data to variables.
For example I got the following error:

-->[fid,err] = mopen('test1.csv','rb')
err =

0.
fid =

1.

-->xxx = read(1,11,8)
!--error 243
C file logical unit not allowed here

!--error 49
incorrect file or format


The data in the file basically look like

ABS
-30
30
10
5
0.35 0.346 -1.142859
0.177 0.205 0.238 0.279 0.314 0.371 0.409 0.444
0.169 0.206 0.243 0.29 0.323 0.374 0.411 0.435
0.161 0.203 0.231 0.272 0.321 0.364 0.399 0.428
0.162 0.197 0.221 0.269 0.312 0.368 0.399 0.42
0.153 0.185 0.22 0.274 0.313 0.356 0.382 0.42

etc.

Thanks a lot for your help!
Grace

Francois Vogel

unread,
Aug 7, 2007, 2:34:55 AM8/7/07
to
> The data in the file basically look like
>
> ABS
> -30
> 30
> 10
> 5
> 0.35 0.346 -1.142859
> 0.177 0.205 0.238 0.279 0.314 0.371 0.409 0.444
> 0.169 0.206 0.243 0.29 0.323 0.374 0.411 0.435
> 0.161 0.203 0.231 0.272 0.321 0.364 0.399 0.428
> 0.162 0.197 0.221 0.269 0.312 0.368 0.399 0.42
> 0.153 0.185 0.22 0.274 0.313 0.356 0.382 0.42

I would use something like:

fd=mopen("myfile.csv");
// read header
he=mgetl(fd,6);
// process header
// ... use msscanf on he elements ...
// read data
da=mgetl(fd,-1);
mclose(fd);
//process data
//...

--
Francois Vogel
1-888-MY-ETHER ext. 01907199
<http://www.ether.com/CallButton/Francois-Vogel/6887475.aspx>
<http://www.ether.com>

0 new messages