[scilab-Users] Re: uploading a file txt

Mathieu Dubois mathieu.dubois at limsi.fr
Tue Jul 5 14:52:12 CEST 2011


On 07/05/2011 11:51 AM, Chiara wrote:
> Hi!
> Thanks for your answer. My mistake was to keep the heading (even if
> commented) in the txt file. Anyway now the matrix is correctly uploaded.
>
> Two more issues...
>
> In order to save the new matrix and I wrote the command "save('M_new.txt')"
> but a matrix like the following is saved. Is it a problem of format?
>
>   âã@     âã@     âã@     âã@     âã@     âã@     âã@     âã@     âã@     âã@
> âã@     âã@     âã@     âã@     âã@     âã@     âã@     âã@     âã@     âã@
> âã@     âã@     âã@     âã@     âã@     âã@     âã@     âã@     âã@     âã@
> âã@     âã@     âã@     âã@     âã@     âã@     âã@     âã@     âã@     âã@
> âã@     âã@     âã@     âã@     âã@     âã@     âã@     âã@     âã@     âã@
As stated by the help page save use a binary format.
If you want to use a text format use mfprintf.
In you case:

fd2 = mopen('new_file.txt', 'w')
mfprintf(fd2,"%f\t%f\t%f\t%f\t%f\t%f\t%f\n", M);
mclose(fd);

should work (\t is to use tabs as column separator instead of white space).
Note that the 2 files won't be exactly identical (but you can play with 
format specifier: for instance your 1st and 6th column looks like 
intergers so use %d, others columns seems to have 2 digits so use %.2f 
instead of %f).

Generally speaking scilab IO function works in pair:
  - save-load: binary
  - fprintfMat-fscanfMat: text format for matrices
  - mfprintff-mfscanf: general text format
  - write_csv-read_csv
When you have a problem with a function first read the help page.

> âã@     âã@
>
> I'd like to delete the rows corresponding to NaN values. In matlab I used
> the following command:
> M_new(or(isnan(M_new)'),:) = []
> In scilab it doesn't seem to work. Is there a similar functions?
In Matlab, or  computes the logical or of every column and therefore 
returns a vector.
In scilab, or(a)  computes the logical or of every elements and 
therefore returns a scalar.
or(a,2) operates on rows.

Therefore :
M_new(or(isnan(M_new), 2),:) = [];
should work.
> Thanks again for your help
>
> Chiara
>
>
>
> --
> View this message in context: http://mailinglists.scilab.org/uploading-a-file-txt-tp3090694p3140221.html
> Sent from the Scilab users - Mailing Lists Archives mailing list archive at Nabble.com.




More information about the users mailing list