フィルターのクリア

Get the numeric value of a variable using sprintf

2 ビュー (過去 30 日間)
Alexandre
Alexandre 2015 年 10 月 25 日
編集済み: Stephen23 2019 年 6 月 19 日
Hi,
How can I get the numerical value of a variable doing something like this:
num_1=2;
num_2=5;
num=3=9;
random_num=randsample([1 2 3],1)
Time=sprintf('num_%d',random_num)
Then I get Time=num_X but what I want is to get the numerical value associated to num_X
Any clue on how to do it?
Thank you very much.

採用された回答

Star Strider
Star Strider 2015 年 10 月 25 日
The only way I can think to do it is to use the ‘evil eval’:
Time - num_2
Time = eval(Time)
Time =
5
But as Walter wrote, it’s best to avoid it altogether.

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2015 年 10 月 25 日

カテゴリ

Help Center および File ExchangeDescriptive Statistics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by