Input file editing format
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
RAKESH KUMAR TOTA
le 20 Jan 2021
Commenté : RAKESH KUMAR TOTA
le 20 Jan 2021
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 commentaires
Bob Thompson
le 20 Jan 2021
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?
Réponse acceptée
Mathieu NOE
le 20 Jan 2021
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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Environment and Settings dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!