Get horizontal (row) data from a txt file (table) with a reguler-pattern rows (series)
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Tyann Hardyn
el 17 de Jul. de 2021
Comentada: Tyann Hardyn
el 4 de Sept. de 2021
Hi everyone, i wanna ask about how to get a horizontal data from a txt file with a reguler series. So i have this kind of data (with a new header for every 30 row) :
I want to get the data in green rectangular (row 2, column 1) as 1st data, data in orange rectangular (row 2, column 5) as 2nd data, data in black rectangular (row 3, column 1) as 3rd, data in purple rectangular (row 3, column 5) as 4th data, and continuously loop with this pattern until it stopped at (row 30, column 5) as final data so that make total 60 data (1st data, 2nd data.... 60th data) before it get reach a new header again. I want make the withdrawed data to become just 1 column like this :
Horizontal Component
1st data
2nd data
3rd data
4th data
.
.
.
60th data
So then i can plot it as a time dependent curve. But firstly, i need to get a script how to get or convert that kind of data to become a column data like that.... I want to get the data from uigetfile function :
[filename,direct]=uigetfile({'*.txt', 'Text-files (*.txt)'},'Load IMF Magnet Data');
full = fullfile(direct, filename);
The data i gave before was a .imf formatted, but it doesnt matter as it can be converted from .imf to .txt before, so i can get the .txt file from uigetfile until it can be writted again in a new file with :
[savefile, direct, default] = uiputfile('*.txt', 'Save As', 'New Data');
eval(['cd ''' direct ''';']);
fout=fopen(savefile,'w');
. But i didnt know how to handle the data after uigetfile function was started to get the data i need (its kinda too difficult to me)....
Would you mind to help my problem here. Thank you very much everyone....
0 comentarios
Respuesta aceptada
Simon Chan
el 17 de Jul. de 2021
Use readmatrix to retrieve the data in the file as follows:
B = readmatrix(full);
Data1 = B(1:2:30,1);
Data2 = B(1:2:30,5);
Data3 = B(2:2:30,1);
Data4 = B(2:2:30,5);
Data=[Data1, Data2, Data3, Data4]';
Data = Data(:);
plot(Data)
12 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Text Files en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!