Access data using genvarname

1 回表示 (過去 30 日間)
Léon
Léon 2013 年 5 月 20 日
Hello,
I got the following question and hope that you can point me to the right direction. Consider the following:
a = 5;
b = struct;
b.data_5 = dataset;
c = genvarname(['b.data_' num2str(a)]);
c should now contain the dataset stored in b.data_5, can you help me how to achieve that? The problem is that a is dynamic, otherwise there wouldn't be such a problem.
Thank you very much.

採用された回答

Sean de Wolski
Sean de Wolski 2013 年 5 月 20 日
編集済み: Sean de Wolski 2013 年 5 月 20 日
How about just using dynamic fieldnames?
a.someString = pi
fn = fieldnames(a);
a.(fn{1})
What are you trying to do?
For your example:
b.a5 = pi
b.(['a' num2str(5)])
  1 件のコメント
Léon
Léon 2013 年 5 月 20 日
OMG, of course. Sorry just didn't see it after some hours of coding and went crazy about that not working. :-) THX

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

その他の回答 (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