Info
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
trouble for importing a data file
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi,
I want to import a *.asc file. The file has data something like below.
0.021780 2 768 Rx d 8 21 62 254 157 2 39 255 242
0.042450 2 768 Rx d 8 21 16 2 62 0 158 255 246
I'm tried different commands, but I'm not able to load this as per my requirements.
I tried to use 'importdata' function as shown below
"[A] = importdata('CANOE10.asc', '\t');"
When I use this, all the data is stored in single cell as it is in the file. But, I want to store the data separately in different variables like
A1 = 21, B1= 62, C1 = 254, D1 = 157 etc..
I even tried 'textread' function as like below.
"[C, D, E, F, G, H] = textread('CANOE10.asc', '%s %s %s %s %s %d'); " Using this function, the data was able to store in different variables, but its not able to store consistently.
Kindly help me please.
0 comentarios
Respuestas (2)
Geoff
el 15 de Mzo. de 2012
Using textread is fine here.
But you need to include as many fields in your format string as you expect to see in the file, starting from the first. Even if you don't care about the first few columns.
Looking at that example data, I would use the format:
'%f%d%d%s%s%d%d%d%d%d%d%d%d%d'
You have to specify that many variables on the left though.
If you go back to your importdata version, it might be easier.
in = importdata('CANOE10.asc', '\t');
A = in.data(:,1);
B = in.data(:,2);
C = in.data(:,3);
% etc...
2 comentarios
Geoff
el 15 de Mzo. de 2012
Is your data _actually_ tab-delimited? If not, then specifying that it is will cause each row to be read into a single string.
I checked my code by copying your lines verbatim into a file and calling importdata('CANOE10.asc'); That will use spaces as the delimiter, and behaves correctly.
La pregunta está cerrada.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!