Discussion:
[Scilab-users] Read matrix from text file
Frieder Nikolaisen
2017-03-20 16:26:14 UTC
Permalink
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')
Tim Wescott
2017-03-20 16:53:25 UTC
Permalink
Post by Frieder Nikolaisen
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
 
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.)
--
Tim Wescott
www.wescottdesign.com
Control & Communications systems, circuit & software design.
Phone: 503.631.7815
Cell: 503.349.8432
Frieder Nikolaisen
2017-03-21 08:10:15 UTC
Permalink
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:Usersf.nikolaisenDocumentsBachelorarbeitSimulationKoeffizienten_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
Post by Tim Wescott
On
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')
Post by Tim Wescott
Scilab has multiple contradictory ways of
managing files. It appears
Post by Tim Wescott
that "mopen" is not compatible with "read".
-->file("open", "bob.txt", "old");
-->read(bob,
-1, 4)
Post by Tim Wescott
ans =
1. 2. 3. 4.
5. 6. 7. - 8.
-->file("close",
bob);
Post by Tim Wescott
However, if you can trust that your file will always be in a
tidy
Post by Tim Wescott
-->fscanfMat("bob.txt")
ans
=
Post by Tim Wescott
1. 2. 3. 4.
5. 6. 7. - 8.
(You can also use mopen and
mfscanf -- the "file" stuff is "Fortran-
Post by Tim Wescott
like", the "mopen" stuff is
"C-like", and fscanfMat is just convenient.
Post by Tim Wescott
I tend to use the C-like
stuff because most of my "real" programming
Post by Tim Wescott
work is done in C, so I'm
familiar with it. Pick your poison.)
Tim Wescott
2017-03-21 20:55:48 UTC
Permalink
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.
Post by Frieder Nikolaisen
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
 
 
Post by Tim Wescott
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
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
-->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
-->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
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
Samuel Gougeon
2017-03-21 22:20:25 UTC
Permalink
Post by Frieder Nikolaisen
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.
Do you mean: some initial rows of text?
Then you may rather use csvRead():
https://help.scilab.org/docs/6.0.0/en_US/csvRead.html
and its last input argument "header"
Post by Frieder Nikolaisen
Koeffizienten_DM=file("open", "C:\Users\f.nikolaisen\Documents\Bachelorarbeit\Simulation\Koeffizienten_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?
Koeffizienten_Pfad = uigetfile(["*.txt"],'',"Wählen Sie die Datei Koeffizienten");

Koeffizienten_DM= file("open",Koeffizienten_Pfad, "old");
Post by Frieder Nikolaisen
And having there not an abselout path, but the current directory opened.
Koeffizienten_DM= file("open","Koeffizienten_DM_Matrix.txt", "old");
Post by Frieder Nikolaisen
Sorry for this beginners questions, its really hard to get this
details with the Scilab help.
The multiple sections about files are likely the worst.

Osvaldo Sergio Farhat de Carvalho
2017-03-20 17:30:23 UTC
Permalink
_______________________________________________
users mailing list
***@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users
Frieder Nikolaisen
2017-03-20 18:13:41 UTC
Permalink
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
Hi Frieder,
Try
Koeffizienten_Pfad = uigetfile(["*.txt"],'',"Wählen Sie die Datei Koeffizienten");
m = fscanfMat(Koeffizienten_Pfad)
disp(B)
Regards,
Osvaldo
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
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
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
http://lists.scilab.org/mailman/listinfo/users
Tim Wescott
2017-03-20 18:25:49 UTC
Permalink
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.
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 
Hi Frieder,
Try
Koeffizienten_Pfad = uigetfile(["*.txt"],'',"Wählen Sie die Datei
Koeffizienten");
m = fscanfMat(Koeffizienten_Pfad)
disp(B)
Regards,
Osvaldo
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
 
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
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
http://lists.scilab.org/mailman/listinfo/users
 
_______________________________________________
users mailing list
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
Stefan Du Rietz
2017-03-20 17:44:18 UTC
Permalink
Hello Frieder, have you tried just this?

Koeffizienten_Pfad = uigetfile(["*.txt"],'',"Wählen Sie die Datei
Koeffizienten");

B = read(Koeffizienten_Pfad,-1,4)

Redards
Stefan
Post by Frieder Nikolaisen
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
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
http://lists.scilab.org/mailman/listinfo/users
Continue reading on narkive:
Loading...