Question about getting text from a file
Mostrar comentarios más antiguos
Hello,
I am creating a program that is gathering information from a file listing data values, an alphanumeric call sign, and date. I can access the data, and am trying to get the call signs in the third column. I would like to use these call signs to group the data values and dates for a plot. The .dat file is similar to this:
-55.00** 6.30** 2086** 2011-11-11 01**<br>
21.70** -17.70** 2AJI3** 2011-11-07 18**<br>
20.20** -17.80** 2AJI3** 2011-11-07 22**<br>
17.50** -17.80** 2AJI3** 2011-11-08 06**
Where * represents a spacing. (not all spacings are the same) So I can get the information from a textread command that puts it all in a 1 by X matrix where x is the total number of lines.
load 'sample.dat';
la = sample(:,1); %gets column 1 from file%
lo = sample(:,2); %gets column 2 from file%
sh = sample(:,3); %gets column 3 from file% (needs to be a string)
yr = sample(:,4); %gets column 4 from file (needs to reflect actual date, or just be a string)%
pos = [la,lo];
data = textread('sample.dat','%s','delimiter','\n','whitespace','');
[col1, col2, col3] = textread('sample.dat','%n%n%n%*[\n]','delimiter',' ');
Now the textread at the bottom will get a col3 that is the correct length, but will truncate everything after the 2 of the third column. So, 2AJI3 will only return as 2 in the matrix I am creating. I would like to try and use textscan, but I have an older version of matlab, and do not know if I can update.
I know this is long, and I apologize, I am just trying to get the most information down that might help. Please be patient with me as I have not done this sort of data sorting before.
Thanks in advance.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Data Import and Export en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!