Put .txt data in matrix

classic Classic list List threaded Threaded
11 messages Options
simon_37 simon_37
Reply | Threaded
Open this post in threaded view
|

Put .txt data in matrix

Hi everybody,

I want to extract data from .txt in matrix for plot a graphic.
Unfortunaly files .txt have some headers
For example :
                Constante de temps : 2Nombre de cycles : 2
 ms
Sensibilité : 100 microV
Tension AC de lecture : 1.000000E+3mV
Fréquence AC de lecture : 3.700000E+0kHz
A min : -5.000000E+0 V
A max : 5.000000E+0 V
Pas de tension : 100.000000E-3 V
Durée totale du cycle : 150.000000E+0 ms
Durée de l'impulsion de tension : 150.000000E+0 ms
Commentaires : d:\labview\20131125_161108_LL072
Informations sur la pointe :
Colonnes 1 et 2 : X,Y de AIO, colonnes 3 et 4 : voies X,Y de AI1
/end

0.000 2.848 0.000 0.628
0.100 2.535 0.100 0.733
0.200 3.562 0.200 1.021
0.300 3.111 0.300 0.620
0.400 2.746 0.400 0.693
0.500 2.739 0.500 0.860
0.600 3.001 0.600 1.126
0.700 2.306 0.700 0.967
0.800 2.452 0.800 0.706
0.900 2.551 0.900 1.046
1.000 3.865 1.000 0.966
1.100 2.161 1.100 0.987
....

I already use the function read or functions mopen and mgetl and it doesn't work...
I search the mean to begin the read at line number 15 of my file.
I am trap.

Regards
Simon.
Stanislav Stanislav
Reply | Threaded
Open this post in threaded view
|

Re: Put .txt data in matrix

Hi.
Try fscanfMat.

Stanislav
11.12.2013 21:12, simon_37 пишет:

> Hi everybody,
>
> I want to extract data from .txt in matrix for plot a graphic.
> Unfortunaly files .txt have some headers
> For example :
> Constante de temps : 2Nombre de cycles : 2
>   ms
> Sensibilité : 100 microV
> Tension AC de lecture : 1.000000E+3mV
> Fréquence AC de lecture : 3.700000E+0kHz
> A min : -5.000000E+0 V
> A max : 5.000000E+0 V
> Pas de tension : 100.000000E-3 V
> Durée totale du cycle : 150.000000E+0 ms
> Durée de l'impulsion de tension : 150.000000E+0 ms
> Commentaires : d:\labview\20131125_161108_LL072
> Informations sur la pointe :
> Colonnes 1 et 2 : X,Y de AIO, colonnes 3 et 4 : voies X,Y de AI1
> /end
>
> 0.000 2.848 0.000 0.628
> 0.100 2.535 0.100 0.733
> 0.200 3.562 0.200 1.021
> 0.300 3.111 0.300 0.620
> 0.400 2.746 0.400 0.693
> 0.500 2.739 0.500 0.860
> 0.600 3.001 0.600 1.126
> 0.700 2.306 0.700 0.967
> 0.800 2.452 0.800 0.706
> 0.900 2.551 0.900 1.046
> 1.000 3.865 1.000 0.966
> 1.100 2.161 1.100 0.987
> ....
>
> I already use the function read or functions mopen and mgetl and it doesn't
> work...
> I search the mean to begin the read at line number 15 of my file.
> I am trap.
>
> Regards
> Simon.
>
>
>
>
> --
> View this message in context: http://mailinglists.scilab.org/Put-txt-data-in-matrix-tp4028011.html
> Sent from the Scilab users - Mailing Lists Archives mailing list archive at Nabble.com.
> _______________________________________________
> users mailing list
> [hidden email]
> http://lists.scilab.org/mailman/listinfo/users

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
simon_37 simon_37
Reply | Threaded
Open this post in threaded view
|

Re: Put .txt data in matrix

It doesn't work to, I already try it.
It return me error 999
Christophe Dang Ngoc Chan Christophe Dang Ngoc Chan
Reply | Threaded
Open this post in threaded view
|

Re: Put .txt data in matrix

Hello,

> De : simon_37
>
> [...fscanfMat...]
> It doesn't work to, I already try it.
> It return me error 999

I tried it from the data you gave (copy/paste to a .txt file)
and it worked.

I don't know what error 999 is, it is not in the table
http://help.scilab.org/docs/5.4.1/en_US/error_table.html

Maybe you could send the text file atached so we can see what happens.

Best regards.

--
Christophe Dang Ngoc Chan
Mechanical calculation engineer

______________________________________________________________________

This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error), please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.
______________________________________________________________________
_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
--
Christophe Dang Ngoc Chan
Mechanical calculation engineer
Osvaldo Carvalho Osvaldo Carvalho
Reply | Threaded
Open this post in threaded view
|

Re: Put .txt data in matrix

In reply to this post by simon_37
If you want to ignore exactly the first 15 lines, you can use:

f = mopen("your file","r");
garbage = mgetl(f,15);
m = [];
while not meof(f)
    line = mgetl(f,1); // read one line
    lineNr = eval(tokens(line))'; // dont forget the '
    m = [m;lineNr]; // add one line to m
end

-----"users" <[hidden email]> escreveu: -----
Para: [hidden email]
De: simon_37
Enviado por: "users"
Data: 11/12/2013 01:50 PM
Assunto: Re: [Scilab-users] Put .txt data in matrix

It doesn't work to, I already try it.
It return me error 999



--
View this message in context: http://mailinglists.scilab.org/Put-txt-data-in-matrix-tp4028011p4028013.html
Sent from the Scilab users - Mailing Lists Archives mailing list archive at Nabble.com.
_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Antoine Monmayrant Antoine Monmayrant
Reply | Threaded
Open this post in threaded view
|

Re: Put .txt data in matrix

In reply to this post by simon_37
Le 11/12/13 16:12, simon_37 a écrit :
> Hi everybody,

Hi Simon,

Can you send us the raw txt file to see what we can do?
Usually the new csv functions should work, the only difficulty is being
able to understand how to use the regular expression system to get rid
of the comments.

Cheers,

Antoine

>
> I want to extract data from .txt in matrix for plot a graphic.
> Unfortunaly files .txt have some headers
> For example :
> Constante de temps : 2Nombre de cycles : 2
>   ms
> Sensibilité : 100 microV
> Tension AC de lecture : 1.000000E+3mV
> Fréquence AC de lecture : 3.700000E+0kHz
> A min : -5.000000E+0 V
> A max : 5.000000E+0 V
> Pas de tension : 100.000000E-3 V
> Durée totale du cycle : 150.000000E+0 ms
> Durée de l'impulsion de tension : 150.000000E+0 ms
> Commentaires : d:\labview\20131125_161108_LL072
> Informations sur la pointe :
> Colonnes 1 et 2 : X,Y de AIO, colonnes 3 et 4 : voies X,Y de AI1
> /end
>
> 0.000 2.848 0.000 0.628
> 0.100 2.535 0.100 0.733
> 0.200 3.562 0.200 1.021
> 0.300 3.111 0.300 0.620
> 0.400 2.746 0.400 0.693
> 0.500 2.739 0.500 0.860
> 0.600 3.001 0.600 1.126
> 0.700 2.306 0.700 0.967
> 0.800 2.452 0.800 0.706
> 0.900 2.551 0.900 1.046
> 1.000 3.865 1.000 0.966
> 1.100 2.161 1.100 0.987
> ....
>
> I already use the function read or functions mopen and mgetl and it doesn't
> work...
> I search the mean to begin the read at line number 15 of my file.
> I am trap.
>
> Regards
> Simon.
>
>
>
>
> --
> View this message in context: http://mailinglists.scilab.org/Put-txt-data-in-matrix-tp4028011.html
> Sent from the Scilab users - Mailing Lists Archives mailing list archive at Nabble.com.
> _______________________________________________
> users mailing list
> [hidden email]
> http://lists.scilab.org/mailman/listinfo/users
>

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Serge Steer-3 Serge Steer-3
Reply | Threaded
Open this post in threaded view
|

Re: Put .txt data in matrix

In reply to this post by simon_37

The fscanfMat function should do the job
Serge Steer
----- Mail original -----

> De: "simon_37" <[hidden email]>
> À: [hidden email]
> Envoyé: Mercredi 11 Décembre 2013 16:12:48
> Objet: [Scilab-users] Put .txt data in matrix
>
> Hi everybody,
>
> I want to extract data from .txt in matrix for plot a graphic.
> Unfortunaly files .txt have some headers
> For example :
> Constante de temps : 2Nombre de cycles : 2
>  ms
> Sensibilité : 100 microV
> Tension AC de lecture : 1.000000E+3mV
> Fréquence AC de lecture : 3.700000E+0kHz
> A min : -5.000000E+0 V
> A max : 5.000000E+0 V
> Pas de tension : 100.000000E-3 V
> Durée totale du cycle : 150.000000E+0 ms
> Durée de l'impulsion de tension : 150.000000E+0 ms
> Commentaires : d:\labview\20131125_161108_LL072
> Informations sur la pointe :
> Colonnes 1 et 2 : X,Y de AIO, colonnes 3 et 4 : voies X,Y de AI1
> /end
>
> 0.000 2.848 0.000 0.628
> 0.100 2.535 0.100 0.733
> 0.200 3.562 0.200 1.021
> 0.300 3.111 0.300 0.620
> 0.400 2.746 0.400 0.693
> 0.500 2.739 0.500 0.860
> 0.600 3.001 0.600 1.126
> 0.700 2.306 0.700 0.967
> 0.800 2.452 0.800 0.706
> 0.900 2.551 0.900 1.046
> 1.000 3.865 1.000 0.966
> 1.100 2.161 1.100 0.987
> ....
>
> I already use the function read or functions mopen and mgetl and it
> doesn't
> work...
> I search the mean to begin the read at line number 15 of my file.
> I am trap.
>
> Regards
> Simon.
>
>
>
>
> --
> View this message in context:
> http://mailinglists.scilab.org/Put-txt-data-in-matrix-tp4028011.html
> Sent from the Scilab users - Mailing Lists Archives mailing list
> archive at Nabble.com.
> _______________________________________________
> users mailing list
> [hidden email]
> http://lists.scilab.org/mailman/listinfo/users
>
_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
simon_37 simon_37
Reply | Threaded
Open this post in threaded view
|

Re: Put .txt data in matrix

In reply to this post by Osvaldo Carvalho
Hi Osvaldo,

Thanks for your reply.
I think your "piece" of code is the most efficient that I search.
But Scilab don't recognize the "not" in the while loop parameters...
I am trap.

Regards
Simon



2013/12/11 Osvaldo Carvalho [via Scilab / Xcos - Mailing Lists Archives] <[hidden email]>
If you want to ignore exactly the first 15 lines, you can use:

f = mopen("your file","r");
garbage = mgetl(f,15);
m = [];
while not meof(f)
    line = mgetl(f,1); // read one line
    lineNr = eval(tokens(line))'; // dont forget the '
    m = [m;lineNr]; // add one line to m
end

-----"users" <[hidden email]> escreveu: -----
Para: [hidden email]
De: simon_37
Enviado por: "users"
Data: 11/12/2013 01:50 PM
Assunto: Re: [Scilab-users] Put .txt data in matrix

It doesn't work to, I already try it.
It return me error 999



--
View this message in context: http://mailinglists.scilab.org/Put-txt-data-in-matrix-tp4028011p4028013.html

Sent from the Scilab users - Mailing Lists Archives mailing list archive at Nabble.com.
_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users



If you reply to this email, your message will be added to the discussion below:
http://mailinglists.scilab.org/Put-txt-data-in-matrix-tp4028011p4028015.html
To unsubscribe from Put .txt data in matrix, click here.
NAML

GOBILLOT Gilles 116128 GOBILLOT Gilles 116128
Reply | Threaded
Open this post in threaded view
|

Re: Put .txt data in matrix

I use to read text files with Scilab. This piece of code is close to the one I use.

 

To save time, one can give a dimension to ‘m’ :

Instead of m=[]

Prefer m=zeros(10000,4); // by-exemple

 

 

Gilles

Tel : +33 (0)4 42 25 20 33 -  Mob : +33 (0) 6 87 99 19 57 - Fax : +33 (0)4 42 25 49 17

[hidden email]

 

 

De : users [mailto:[hidden email]] De la part de simon_37
Envoyé : jeudi 12 décembre 2013 10:46
À : [hidden email]
Objet : Re: [Scilab-users] Put .txt data in matrix

 

Hi Osvaldo,

Thanks for your reply.

I think your "piece" of code is the most efficient that I search.

But Scilab don't recognize the "not" in the while loop parameters...

I am trap.

Regards

Simon

 

 

2013/12/11 Osvaldo Carvalho [via Scilab / Xcos - Mailing Lists Archives] <[hidden email]>

If you want to ignore exactly the first 15 lines, you can use:

f = mopen("your file","r");
garbage = mgetl(f,15);
m = [];
while not meof(f)
    line = mgetl(f,1); // read one line
    lineNr = eval(tokens(line))'; // dont forget the '
    m = [m;lineNr]; // add one line to m
end

-----"users" <[hidden email]> escreveu: -----

Para: [hidden email]
De: simon_37
Enviado por: "users"
Data: 11/12/2013 01:50 PM
Assunto: Re: [Scilab-users] Put .txt data in matrix

It doesn't work to, I already try it.
It return me error 999


--
View this message in context: http://mailinglists.scilab.org/Put-txt-data-in-matrix-tp4028011p4028013.html


Sent from the Scilab users - Mailing Lists Archives mailing list archive at Nabble.com.
_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users


_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users


If you reply to this email, your message will be added to the discussion below:

http://mailinglists.scilab.org/Put-txt-data-in-matrix-tp4028011p4028015.html

To unsubscribe from Put .txt data in matrix, click here.
NAML

 

 


View this message in context: Re: Put .txt data in matrix
Sent from the Scilab users - Mailing Lists Archives mailing list archive at Nabble.com.


_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
simon_37 simon_37
Reply | Threaded
Open this post in threaded view
|

Re: Put .txt data in matrix

Thanks you to everyone for their help.
It's finally done.

I drop my code :

[FileName,PathName] = uigetfile('','','sélectionnez le(s) fichier(s) à traiter',%t);
f = fullfile(PathName, FileName)
f1 = mopen(f,"r");
garbage = mgetl(f1,15);
m = [];
while ~meof(f1)
        line = mgetl(f1,1) // read one line
        if line == [] then
            break
        end
        lineNr = eval(tokens(line))' // dont forget the '
        m = [m;lineNr] // add one line to m  
end

x1=m(:,1)
y1=m(:,2)
x2=m(:,3)
y2=m(:,4)

plot(x1,y1)

Regards
Simon
Osvaldo Carvalho Osvaldo Carvalho
Reply | Threaded
Open this post in threaded view
|

Re: Put .txt data in matrix

In reply to this post by simon_37
Ooops:

while ~meof ....

-----"users" <[hidden email]> escreveu: -----
Para: [hidden email]
De: simon_37
Enviado por: "users"
Data: 12/12/2013 07:46 AM
Assunto: Re: [Scilab-users] Put .txt data in matrix

Hi Osvaldo,

Thanks for your reply.
I think your "piece" of code is the most efficient that I search.
But Scilab don't recognize the "not" in the while loop parameters...
I am trap.

Regards
Simon



2013/12/11 Osvaldo Carvalho [via Scilab / Xcos - Mailing Lists Archives] < [hidden email]>
If you want to ignore exactly the first 15 lines, you can use:

f = mopen("your file","r");
garbage = mgetl(f,15);
m = [];
while not meof(f)
    line = mgetl(f,1); // read one line
    lineNr = eval(tokens(line))'; // dont forget the '
    m = [m;lineNr]; // add one line to m
end

-----"users" < [hidden email]> escreveu: -----
Para: [hidden email]
De: simon_37
Enviado por: "users"
Data: 11/12/2013 01:50 PM
Assunto: Re: [Scilab-users] Put .txt data in matrix

It doesn't work to, I already try it.
It return me error 999



--
View this message in context: http://mailinglists.scilab.org/Put-txt-data-in-matrix-tp4028011p4028013.html

Sent from the Scilab users - Mailing Lists Archives mailing list archive at Nabble.com.
_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users



If you reply to this email, your message will be added to the discussion below:
http://mailinglists.scilab.org/Put-txt-data-in-matrix-tp4028011p4028015.html
To unsubscribe from Put .txt data in matrix, click here.
NAML



View this message in context: Re: Put .txt data in matrix
Sent from the Scilab users - Mailing Lists Archives mailing list archive at Nabble.com.
_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users