プログラム内で変数を​動的に定義および参照​する方法はありません​か?

プログラム内で n の値が変更可能で、n 個の変数を動的に定義及び参照したいと考えています。

 Accepted Answer

MathWorks Support Team
MathWorks Support Team on 25 Oct 2013

0 votes

MATLAB のセル配列を使用する方法があります。
例:
numArrays = 10;
% 定義
A = cell(numArrays,1);
for n = 1:numArrays
A{n} = magic(n);
end
% 参照
for n = 1:numArrays
A{n}
end
また、関連ソリューションには関数 EVAL を用いてA1、A2、…、An のように変数を定義する方法が詳細されています。

More Answers (0)

Categories

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

Products

Community Treasure Hunt

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

Start Hunting!