フィルターのクリア

Importing and naming files in a loop

2 ビュー (過去 30 日間)
sarah Abdellahi
sarah Abdellahi 2018 年 9 月 25 日
コメント済み: Stephen23 2018 年 9 月 25 日
Friends :)
I want to import several files sequentially. In each step, I want the required data to be extracted and then stored in a variable. I have problem storing the data I know its a wrong way to write it, but to explain what I mean, here is how I would like them to load in matlab. Thank you
for i=1:65
load(['DATA_' num2str(i) '.mat'])
Test(i)_1L=(((cDA_1L_WS.DATA.*1000)-4)/0.2133.*3.6/1.608);
Test(i)_2L=(((cDA_2L_WS.DATA.*1000)-4)/0.2133.*3.6/1.608);
end
In other words, my output vectors would be like:
Test1_1L, Test1_2L, Test2_1L,Test2_2L, Test3_1L ,Test3_2L ...
  1 件のコメント
Stephen23
Stephen23 2018 年 9 月 25 日
As Fangjun Jiang wrote, magically changing variable names like that not recommended. Dynamically creating or accessing variable names is one way that beginners force themselves into writing slow, complex, buggy code that is hard to debug. Read this to know why:
You should use neat, simple, and very efficient indexing, exactly as Fangjun Jiang showed.

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

採用された回答

Fangjun Jiang
Fangjun Jiang 2018 年 9 月 25 日
Without more details, the first thing to correct is the variable name
Test(i)_1L should be Test_1L(i)
  2 件のコメント
sarah Abdellahi
sarah Abdellahi 2018 年 9 月 25 日
Thank you for your response.
I think I am not clear enough. "1L" is measured in several tests. I want to extract all "1L" and store them based on their associated test number. If I am not wrong, what you suggested updates L not test number in each iteration.
Fangjun Jiang
Fangjun Jiang 2018 年 9 月 25 日
Naming your variables as Test1_1L, Test2_1L, Test3_1L, ... is a bad ideal. There are plenty of Q&As in this forum emphasizing that.
Instead, your data will be stored in the vector Test_1L. Your Test1_1L is in Test_1L(1), Test2_1L is in Test_1L(2), Test3_1L is in Test_1L(3), etc.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by