MATLAB Answers

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

2 views (last 30 days)
jee young yoo
jee young yoo on 26 Nov 2019
Commented: Stephen Cobeldick on 26 Nov 2019
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.

Answers (1)

per isakson
per isakson on 26 Nov 2019
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

Sign in to answer this question.

Tags

Products