Input file editing format
1 次查看(过去 30 天)
显示 更早的评论
Hi, Good morning
I have a text file el.txt which contains 4800 lines . I need to change linesand store in same text file or create a new file which ever it is fine according to user requirement for instance line 1,121,241,361,481,601 , 721,841,961,1081,1201,1321,1441,1561,1681,1801,.....so on to 4681. difference of 120 lines betweeen lines and next starts with line 2,122,242,361..... 4681.... thand next 3,123,243......it contines till 4800 lines. in this sequesnce lines to be stored in text file. Any help in this direction is appreciated. Thank you in advance.
2 个评论
Bob Thompson
2021-1-20
How much of this process do you have so far? Is there a specific issue you're running into, or not sure how to do any of it in Matlab?
采纳的回答
Mathieu NOE
2021-1-20
hello
I believe this code should work - I tested it only with loops = 2 even though I think you need to go up to 120
data = importdata('el.txt');
[m,n] = size(data);
loop = 2
% option 1 : split and save as separate files
for ci = 1:loop
ind = ci:120:m;
data_out = data(ind,:);
filename = ['data' num2str(ci) '.txt'];
writematrix(data_out, filename);
end
% option 2 : or stack vertically and save as one files
data_all = [];
for ci = 1:loop
ind = ci:120:m;
data_out = data(ind,:);
data_all = [data_all;data_out];
end
filename = ['data' num2str(ci) '.txt'];
writematrix(data_all, 'data_stacked.txt');
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Reporting and Database Access 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!