-------------------------------
(1) 1 3 0
(2) 1 8 0
(3) 1 20 0
(4) 1 22 0
(5) 1 23 0
(6) 10 16 0
(7) 10 17 0
(8) 10 18 0
(9) 12 5 0
(10) 12 8 0
(11) 12 9 0
(12) 12 10 0
..
..
..
-------------------------------
(the characters in-between are spaces.)
How do I read it into scilab. I have tried something like
fid = file ('open','unknown','unknown')
[n, p, q, r, s, t, u] = mscanf(fid, '%c%d%c%c%d%d%d');
but this does not seem to work.
Thanks to anyone who answers this.
Regards,
Rio
A easy solution (may be not the most efficient) is to read
your file as string and do the conversion with evstr because
the evaluation of an expression like "(number)" will give
number. So :
Astr = mgetl(myfile);
A = evstr(Astr);
should work. Finally you can put the 2 instructions
in one line:
A = evstr(mgetl(myfile));
hth
Bruno
Thanks a lot Bruno for your help. Here I am dealing with files of the
size 22MB – 480MB, and I have just 1GB of RAM.
I was hoping that some person with more experience would suggest
something. As for now I realized that I need to use ‘mfscanf()' in
place of ‘mscanf()'
That is
[n, p, q, r, s, t, u] = mfscanf(fid, '%c %d %c %c %d %d %d')
seems to do the job. However I hope scilab has some better solution
and someone with more knowledge could answer this.
Regards,
Rio
> Thanks a lot Bruno for your help. Here I am dealing with files of the
> size 22MB – 480MB, and I have just 1GB of RAM.
> I was hoping that some person with more experience would suggest
> something. As for now I realized that I need to use ‘mfscanf()' in
> place of ‘mscanf()'
> That is
>
> [n, p, q, r, s, t, u] = mfscanf(fid, '%c %d %c %c %d %d %d')
>
Well sure that my previous solution works for SMALL files
only and not for yours big files :-)
May be you could try:
[n,c1,v1,c2,v2,v3,v4] = mfscanf(-1,fid,"%c%d%c %d %d %d \n");
which works on the file you have shown in your first post.
Put the -1 at the beginning lets to "re-itere" the reading
until the end of the file (but it seems to need to read the
end of line char and so the \n at the end). Nevertheless as
the integers will be represented by doubles in scilab you
will need a lot of memory ! In particular you will have to
put the scilab stacksize at a high value : for a file like
you have given, n lines will correspond to 4n doubles (plus
c1 and c2 ) that is more than 4n scilab words. For a file
of 1000000 lines you will need more than 4000000 scilab
words and so try to put the stack at:
stacksize(1e7)
hth
Bruno
>
> [n, p, q, r, s, t, u] = mfscanf(fid, '%c %d %c %c %d %d %d')
>
> seems to do the job. However I hope scilab has some better solution
> and someone with more knowledge could answer this.
>
Well sure that my previous solution works for SMALL files
only and not for yours big files :-)
May be you could try:
fid = mopen(my_file);
[n,c1,v1,c2,v2,v3,v4] = mfscanf(-1,fid,"%c%d%c %d %d %d \n");
mclose(fid)