How can I call variable with a name from the value in cell array??

I have multiple variables
AFEN = (1:10)';
AFMN= (2:22)';
AFDN= (11:15)';
SeedValue{1} = 'AFEN'
and I how choose random number in AFEN with using SeedValue?
for exmple, to perform the following function,,
% 'SeedValue' refer to 'AFEN', so if SeedValue changes, always
% refer to the right variables.
randi(max('SeedValue'))
Thanks in advance.

답변 (1개)

per isakson
per isakson 2019년 11월 26일
A variant without eval()
%%
sv.AFEN = (1:10)';
sv.AFMN = (2:22)';
sv.AFDN = (11:15)';
SeedValue = 'AFEN';
%%
rn = randi( max( sv.(SeedValue) ) );
btw: I find the name, SeedValue, misleading

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

태그

질문:

2019년 11월 26일

댓글:

2019년 11월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by