計算結果などから得ら​れた数値を含んだ変数​名を定義できますか?

8 views (last 30 days)
MathWorks Support Team
MathWorks Support Team on 25 Oct 2013
計算結果などから得られた数値を含めた変数名を定義する方法を教えてください。
例えば、
h=figure;
でfigure ウィンドウを新規作成した際に得られた figure のハンドル h に対して、
h=1 の場合はsample_1= …
h=2 の場合はsample_2= …
h=n の場合はsample_n= …
のように変数名を定義したいです。

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 25 Oct 2013
NUM2STR 関数と EVAL 関数を使えば、計算した数値を含めた変数名を定義することが可能です。
・ サンプルコード
h=figure;
eval(['sample_',num2str(h),'=rand(1)'])

More Answers (0)

Categories

Find more on プログラミング in Help Center and File Exchange

Products


Release

R2011a

Community Treasure Hunt

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

Start Hunting!