[Scilab-users] Read matrix from text file

Tim Wescott tim at wescottdesign.com
Tue Mar 21 21:55:48 CET 2017


Really Good Documentation is usually the last thing to get done even on
a commercial product -- there aren't many open-source software projects
that are well documented, and those are often documented separately in
how-to books.

Fortunately, we have things like mailing lists and forums.

The read function takes an optional format string, which, if you don't
provide anything, defaults to reading a line of numbers.  The
documentation says that it's in Fortran format, so you should be able
to find a good book or website on Fortran and find the format you need
to be able to read in a string or a set of strings.

On Tue, 2017-03-21 at 09:10 +0100, Frieder Nikolaisen wrote:
> Thanks alot. It also works with file and read for me. But I still
> don't know how to handle a string header: read: Wrong number of
> output argument(s): 0 expected.
> 
> Koeffizienten_DM=file("open",
> "C:\Users\f.nikolaisen\Documents\Bachelorarbeit\Simulation\Koeffizien
> ten_DM_Matrix.txt", "old")
> 
> E=read(Koeffizienten_DM,-1,4)
> 
> disp(E)
> 
> file('close',Koeffizienten_DM);
> 
> Could I still choose the document as a user? And having there not an
> abselout path, but the current directory opened.
> Sorry for this beginners questions, its really hard to get this
> details with the Scilab help.
> Greetings
> Frieder
>  
>  
> Am 2017-03-20 17:53, schrieb Tim Wescott:
> > On Mon, 2017-03-20 at 17:26 +0100, Frieder Nikolaisen wrote:
> > > Hello, I do try to read a matrix of floating point numbers from a
> > > text file. I want to have floating point numbers in Sciliab. (I
> > > used before mgetl which return strings). I have attached the
> > > example text file and scilab file. The error it says is: read:
> > > Wrong number of output argument(s): 0 expected. Thank you.
> > > Greetings Frieder   My code: Koeffizienten_Pfad =
> > > uigetfile(["*.txt"],'',"Wählen Sie die Datei Koeffizienten");
> > > Koeffizienten = mopen(Koeffizienten_Pfad) B =
> > > read(Koeffizienten,-1,4) disp(B) mclose('all')
> > Scilab has multiple contradictory ways of managing files.  It
> > appears
> > that "mopen" is not compatible with "read".  To use read:
> > 
> > -->file("open", "bob.txt", "old");
> >  
> > -->read(bob, -1, 4)
> >  ans  =
> >  
> >     1.    2.    3.    4.  
> >     5.    6.    7.  - 8.  
> >  
> > -->file("close", bob);
> > 
> > However, if you can trust that your file will always be in a tidy
> > format, you can use fscanfMat:
> > 
> > -->fscanfMat("bob.txt")
> >  ans  =
> >  
> >     1.    2.    3.    4.  
> >     5.    6.    7.  - 8.
> > 
> > (You can also use mopen and mfscanf -- the "file" stuff is
> > "Fortran-
> > like", the "mopen" stuff is "C-like", and fscanfMat is just
> > convenient.
> >  I tend to use the C-like stuff because most of my "real"
> > programming
> > work is done in C, so I'm familiar with it.  Pick your poison.)
>  
>  
> _______________________________________________
> users mailing list
> users at lists.scilab.org
> http://lists.scilab.org/mailman/listinfo/users
-- 

Tim Wescott
www.wescottdesign.com
Control & Communications systems, circuit & software design.
Phone: 503.631.7815
Cell:  503.349.8432






More information about the users mailing list