How can I import programmaticaly a txt file, which contains mixed data, to MATLAB ?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Dimitris Psychas
le 2 Déc 2014
Commenté : Dimitris Psychas
le 2 Déc 2014
My txt file is that called TLE (Two Line Elements) and it's this:
JASON 2
1 33105U 08032A 14332.88896899 -.00000064 00000-0 -14705-4 0 1044
2 33105 066.0425 256.1081 0007712 271.8374 148.6616 12.80931123301319
I want to import it and set some numbers from those lines to variables. How can I do that? For instance, I want to pick a set of columns in the 3rd row (3, 3:7), which is the number 33105, and set it as variable X. I can't do that because data is mixed and when I tried the command textscan I got very incorrect results. Can someone help me?
Thanks in advance
0 commentaires
Réponse acceptée
Guillaume
le 2 Déc 2014
As there does not seem to be any structure to the file, you'll have to parse it using low level functions. Use fopen, fscanf, or fgetl and possibly some regexp, and fclose for example.
fid = fopen('myfile.txt', 'rt');
header = fgetl(fid); %read first line (JASON 2) as string
line2 = fgetl(fid); %read line 2
line3 = fgetl(fid); %read line 3
x = num2str(line3(3:7));
fclose(fid);
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Workspace Variables and MAT Files dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!