Asignar matriz automaticamente.
2 ビュー (過去 30 日間)
古いコメントを表示
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
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
2022 年 5 月 3 日
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.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Text Data Preparation についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!