How can I call variable with a name from the value in cell array??
10 次查看(过去 30 天)
显示 更早的评论
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
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
1 个评论
Stephen23
2019-11-26
More info on how this works:
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!