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

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

 Réponse acceptée

MathWorks Support Team
MathWorks Support Team le 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 のように変数を定義する方法が詳細されています。

Plus de réponses (0)

Catégories

En savoir plus sur プログラミング dans Centre d'aide et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!