![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/687193/image.jpeg)
Get horizontal (row) data from a txt file (table) with a reguler-pattern rows (series)
4 次查看(过去 30 天)
显示 更早的评论
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) :
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/687173/image.png)
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 个评论
采纳的回答
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(:);
plot(Data)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/687193/image.jpeg)
12 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Text Files 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!