Get horizontal (row) data from a txt file (table) with a reguler-pattern rows (series)

조회 수: 3(최근 30일)
Tyann Hardyn
Tyann Hardyn 2021년 7월 17일
댓글: Tyann Hardyn 2021년 9월 4일
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 ''';']);
. 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....

채택된 답변

Simon Chan
Simon Chan 2021년 7월 17일
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(:);
  댓글 수: 12
Tyann Hardyn
Tyann Hardyn 2021년 9월 4일
@Simon Chan I want to ask, Sir. Do you have any idea to create that logic of readmatrix into a readtable instead, Sir? Because i want to read a multifile data and it will not work if using readmatrix....

댓글을 달려면 로그인하십시오.

추가 답변(0개)

Community Treasure Hunt

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

Start Hunting!

Translated by