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

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

 Respuesta aceptada

MathWorks Support Team
MathWorks Support Team el 25 de Oct. de 2013

0 votos

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

Más respuestas (0)

Categorías

Más información sobre プログラミング en Centro de ayuda y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!