how to run same command for sequence of files
Afficher commentaires plus anciens
hi,
I have 100 ascii files containing data + text. for seperate 1 file i can use command as follows to separate data from file. but i want to do same for all 100 files . Is there any way
delimiterln = '\t';
headerlinesln = 0;
F1 = importdata('A1.asc' ,delimiterln, headerlinesln);
save('L1','F1','-ASCII')
Réponses (1)
Rik
le 22 Mai 2019
Use a loop. Using numbered variables is generally a bad idea. Consider using an array to store everything. If you use the same name in your save call, that will make it easier when using load. Note that I removed the -ASCII flag from your code to better illustrate my loading example.
delimiterln = '\t';
headerlinesln = 0;
for nFile=1:100
fname=sprintf('A%d.asc',nFile);
matname=sprintf('L%d.mat',nFile);
F = importdata(fname ,delimiterln, headerlinesln);
save(matname,'F')
end
%when loading data:
L=struct;
for n=1:100
matname=sprintf('L%d.mat',nFile);
L(n)=load(matname);
end
%L is now a struct array with 100 elements, each with a field F
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!