[scilab-Users] Re: uploading a file txt

Mathieu Dubois mathieu.dubois at limsi.fr
Fri Jul 1 13:57:59 CEST 2011


On 07/01/2011 01:16 PM, chiara wrote:
> Mathieu Dubois<mathieu.dubois at ...>  writes:
>
>> Hello,
>> On 06/21/2011 03:41 PM, Chiara wrote:
>>> Dear All,
>>>
>>> I am a new Scilab user.
>>> I am not able to load a file txt in a file.sce.
>>> The error visualized is:
>>>
>>> Warning: file 'grd.txt' already opened in Scilab.
>> This warning comes from the fact that you have used mopen on this file.
>> Try mclose(fd) (where fd is the variable you get from mopen) or
>> mclose('all').
>> However this is not related to your problem.
>>> load('grd.txt');
>>>                  !--error 246
>>> Function not defined for given argument type(s),
>>>
>>>    check arguments or define function %_load for overloading.
>> load is a function to load a scilab variable written with save not to
>> load text files (see help('load')).
>>> How shall I solve the problem?
>> How is you text file formatted?
>>
>> If it is CSV (comma-separated values), try read read_csv.
>>
>> Otherwise you have to open the file (with mopen) and load data with mscanf.
>> If you have some experience in C it should not be a big deal.
>>
>> HTH,
>> Mathieu
>>> Thanks
>>>
>>> Chiara
>>>
>>
> Thanks for your answer,
> I've tried with the fscanfMat (M=fscanfMat(TMPDIR + '/proof.txt')) function in
> order to read the matrix of 7 columns, which is formatted as follows:
> 40705.00	 -2.56	34.07	21.09	83.61	40705.00	 0.00
> 40705.00	 -2.61	34.05	21.09	83.61	40705.00	 0.00
> 40705.00	 -2.56	34.04	21.09	83.69	40705.00	 0.00
> 40705.00	 -2.57	34.03	21.09	83.97	40705.00	 0.00
> 40705.00	 -2.64	34.02	21.09	84.21	40705.00	 0.00
> 40705.00	 -2.54	34.02	21.10	84.25	40705.00	 0.00
> ........................................................
>
> Is it a problem of directory? I saved the sce file and the txt file in the
> temporal directory of scilab.
I dont think so.
fscanfMat works only on files written by fprintfMat and yours doesn't 
seem compatible because it mixes tabs and spaces.

I have tried the simple script:
fd=mopen('proof.txt');
b=mfscanf(-1,fd,"%f %f %f %f %f %f %f\n");
mclose(fd);
It works on your sample.

mfscanf is for reading several lines with the same format (see help). It 
is a very useful function.

HTH,
Mathieu
> Thanks
> Chiara
>




More information about the users mailing list