how to run same command for sequence of files

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')

2 comentarios

Alex Sune
Alex Sune el 22 de Mayo de 2019
Using a loop
Stephen23
Stephen23 el 22 de Mayo de 2019
"Is there any way "
Of course. Start by reading the MATLAB documentation:

Iniciar sesión para comentar.

Respuestas (1)

Rik
Rik el 22 de Mayo de 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

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 22 de Mayo de 2019

Comentada:

el 22 de Mayo de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by