Retreiving values from one structure and saving it to another

1 回表示 (過去 30 日間)
Ashish
Ashish 2014 年 3 月 17 日
コメント済み: Ashish 2014 年 3 月 18 日
I have a structure -MatFile.Project.Planning.A1(A2, A3, etc). I need to access these values with 'i' varying from 1 to 'n'. These values have to be stored in another structure -MatFile.Project.PreProcess.
I have tried using the following code, but it does not seem to work.
for i=1:length(num_sequence)
dat=eval(['MatFile.Project.Planning.A',num2str(i)]);
eval(['MatFile.Project.PreProcess.A',num2str(i)'])=dat;
end
What could be the best way to store the values under 'Planning.A1 (A2)' etc?

採用された回答

Walter Roberson
Walter Roberson 2014 年 3 月 17 日
for i = 1 : length(num_sequence)
fn = sprintf('A%d', i);
MatFile.Project.PreProcess.(fn) = MatFile.Project.Planning.(fn);
end
  1 件のコメント
Ashish
Ashish 2014 年 3 月 18 日
Thanks Walter. You saved my day!

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by