フィルターのクリア

Making a Loop with Strings

80 ビュー (過去 30 日間)
Michael
Michael 2013 年 9 月 16 日
Hello all,
What is the quick way of shortening this code?
Thanks in advance for the help (I'm sure this one's not 'hard' but I don't know the 'easy' way--or anyway).
data_10_100_1=importdata('filename_2.txt');
data_10_100_2=importdata('filename_5.txt');
data_10_100_3=importdata('filename_9.txt');
data_10_100_4=importdata('filename_11.txt');
data_10_100_5=importdata('filename_14.txt');
data_10_100_6=importdata('filename_16.txt');
data_10_100_7=importdata('filename_17.txt');
data_10_100_8=importdata('filename_18.txt');
data_10_100_9=importdata('filename_20.txt');
data_10_100_10=importdata('filename_22.txt');
data_10_100_11=importdata('filename_23.txt');
data_10_100_12=importdata('filename_24.txt');
data_10_100_13=importdata('filename_28.txt');
data_10_100_14=importdata('filename_29.txt');
The answer will be something like:
x = [2 5 9 11 14 16 17 18 20 22 23 24 28 29];
for i =1:14;
data_10_100str2num(i) = importdata('filename_' num2str(x(i)) '.txt')
end; clear i
but this doesn't work... I'm not sure how to fix it. HOw do I make that LHS correct (the RHS is probably also wrong..)
Many thanks, M.A.B.

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 9 月 16 日
編集済み: Azzi Abdelmalek 2013 年 9 月 16 日
Use a cell array
x = [2 5 9 11 14 16 17 18 20 22 23 24 28 29];
for i =1:14;
data_10_100{i} = importdata(sprintf('filename_%d.txt',x(i)));
end;
  3 件のコメント
Michael
Michael 2013 年 9 月 16 日
Thank you kindly! I'll be able to use this forever now! Your help is much appreciated.
Alisson Vinicius Brito Lopes
Alisson Vinicius Brito Lopes 2021 年 1 月 5 日
Thank you !

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by