[Scilab-users] Read matrix from text file

Tim Wescott tim at wescottdesign.com
Mon Mar 20 19:25:49 CET 2017


You can use "Fortran style" ("file" to open and then "read"), or "C-
style" ("mopen" to open and then "mfscanf").  Both read and mfscanf let
you specify the number of lines to read in (note that I've only ever
done this with mfscanf).

You can also (I'm pretty sure) specify a number of lines to read with
mgetl -- this lets you read into a text block, then use whatever
parsing you want to actually read the data.

On Mon, 2017-03-20 at 19:13 +0100, Frieder Nikolaisen wrote:
> Hi Osvaldo, 
> thanks. It does run well. 
> I have different text documents, sometimes I want to skip the header
> or not load the entire document.  I do not find a solution in the
> help. Like with mgetl, just read a few lines as the variabale A and
> then use B for the wanted Matrix. 
> Cheers
> Frieder 
> 
> Am 20.03.2017 um 18:30 schrieb Osvaldo Sergio Farhat de Carvalho:
> > Hi Frieder,
> > 
> > Try
> > 
> > Koeffizienten_Pfad = uigetfile(["*.txt"],'',"Wählen Sie die Datei
> > Koeffizienten");
> > 
> > m = fscanfMat(Koeffizienten_Pfad)
> > 
> > disp(B)
> > 
> > Regards,
> > Osvaldo
> > 
> > -----"users" <users-bounces at lists.scilab.org> escreveu: -----
> > Para: <users at lists.scilab.org>
> > De: Frieder Nikolaisen 
> > Enviado por: "users" 
> > Data: 20/03/2017 01:37 PM
> > Assunto: [Scilab-users] Read matrix from text file
> > 
> > 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')
> > 
> >  
> > _______________________________________________
> > users mailing list
> > users at lists.scilab.org
> > http://lists.scilab.org/mailman/listinfo/users
> > 
> > 
> > [anexo "Dieselmotor_v2.0.sce" removido por Osvaldo Sergio Farhat de
> > Carvalho/PROF/DCC/ICEX/UFMG]
> > [anexo "Koeffizienten_DM_Matrix.txt" removido por Osvaldo Sergio
> > Farhat de Carvalho/PROF/DCC/ICEX/UFMG]
> > 
> > 
> > _______________________________________________
> > users mailing list
> > users at lists.scilab.org
> > http://lists.scilab.org/mailman/listinfo/users
>  
> _______________________________________________
> 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