필터 지우기
필터 지우기

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 CenterFile Exchange에서 Structures에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by