how i can read these datd from text file

1 visualización (últimos 30 días)
ahmed morsi
ahmed morsi el 6 de Jul. de 2015
Editada: Guillaume el 6 de Jul. de 2015
# n JD x dx y dy t F SNR RA dRA DEC dDEC
0001 2456033.58697852 0522.75 00.00 0236.04 00.00 3 T 094.9 22.322920 0.000000 35.83544 0.00000
0002 2456033.58698892 0532.49 00.00 0235.95 00.00 3 S 059.0 22.316349 0.000000 35.79867 0.00000
0003 2456033.58699321 0539.79 00.00 0235.88 00.00 5 S 026.8 22.311426 0.000000 35.77104 0.00000

Respuestas (2)

Walter Roberson
Walter Roberson el 6 de Jul. de 2015
Editada: Walter Roberson el 6 de Jul. de 2015
fmt = [repmat('%f',1, 7), '%c', repmat('%f', 1, 5)];
fid = fopen('YourFile.txt', 'rt');
datacell = textscan(fid, fmt, 'HeaderLines', 1);
fclose(fid);
n = datacell{1};
JD = datacell{2};
x = datacell{3};
etc.
Note: the F will be a character array. If you would prefer a cell array of strings change the %c to %s

Guillaume
Guillaume el 6 de Jul. de 2015
Editada: Guillaume el 6 de Jul. de 2015
Another option:
data = readtable('somefile.txt', 'Delimiter', ' ', 'HeaderLines', 1, 'ReadVariableNames', false)
And if you change your header line so that the first header, # n, is instead a valid matlab variable name (e.g. just n):
data = readtable('somefile.txt', 'Delimiter', ' ')
your table will use your header line to name the columns.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by