how to run same command for sequence of files

2 ビュー (過去 30 日間)
Vishal Dwivedi
Vishal Dwivedi 2019 年 5 月 22 日
コメント済み: Stephen23 2019 年 5 月 22 日
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 件のコメント
Alex Mcaulley
Alex Mcaulley 2019 年 5 月 22 日
Using a loop
Stephen23
Stephen23 2019 年 5 月 22 日
"Is there any way "
Of course. Start by reading the MATLAB documentation:

サインインしてコメントする。

回答 (1 件)

Rik
Rik 2019 年 5 月 22 日
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

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by