필터 지우기
필터 지우기

Asignar matriz automaticamente.

조회 수: 1 (최근 30일)
David Carrillo
David Carrillo 2022년 5월 3일
Hola Comunidad de Mathworks, les quería pedor ayuda acerca de como guardar distintas matrices en variables automaticamente.
Estoy intentando hacer lo siguiente:
a partir de una matriz M(:,:,:)
quiero generar n matrices llamadas M1,M2,M3, etc
donde cada Matriz corresponda a M(:,:,n)
estoy intentando aplicar el siguiente comando, pero solo me funciona con numeros, no con matrices.
for n=1:nf
eval(sprintf(' M%d = n ', Mm(:,:,n)))
end
De modo que quede como sigue:
M1=M(:,:,1)
M2=M(:,:,2)
...
Mn=M(:,:,n)
Agradezco desde ya su ayud.
Saludos cordiales!
  댓글 수: 1
Stephen23
Stephen23 2022년 5월 3일
편집: Stephen23 2022년 5월 3일
"quiero generar n matrices llamadas M1,M2,M3, etc"
The MATLAB documentation states "A frequent use of the eval function is to create sets of variables such as A1, A2, ..., An, but this approach does not use the array processing power of MATLAB and is not recommended."
In fact your approach forces you into writing slow, complex, inefficient, obfuscated, buggy code that is hard to debug. Read this to know why:
It is very very unlikely that you need to do this anyway:

댓글을 달려면 로그인하십시오.

답변 (1개)

Constantino Carlos Reyes-Aldasoro
Hola
Primero te recomendaria escribir en ingles para aumentar la posibilidad de que respondan las preguntas. Segundo, para que quieres crear una nueva matriz de algo que ya tienes como una matriz? No es buena idea crear muchas variables, simplemente usa M(:,:,k) cada vez que necesites evaluar esos datos.

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by