Borrar filtros
Borrar filtros

workspace & LOOP FOR

2 visualizaciones (últimos 30 días)
Marwen Tarhouni
Marwen Tarhouni el 30 de Dic. de 2016
Editada: Stephen23 el 30 de Dic. de 2016
Bonjour,
J'exécuter un algorithme 50 fois en utilisant la boucle for. Je veux sauvegarder les résultats après chaque itération c'est à dire je veux avoir dans le workspace 50 matrices mais je trouve toujours la dernière matrice (pour i=50).j'applique cette boucle sur tout l'algorithme.mon algorithme contient des valeurs randomisées,chaque exécution j'avoir une matrice.je veux avoir 50 matrice de façon automatique en utilisant la boucle For mais je trouve la dernière dans le workspace. Avez vous une idée ?
Merci

Respuesta aceptada

Stephen23
Stephen23 el 30 de Dic. de 2016
Editada: Stephen23 el 30 de Dic. de 2016
"Avez vous une idée ?"
yes: don't do this. Read this to know why:
No matter how much beginners love to invent the idea of dynamically naming their variables, it is a slow, buggy, and obfuscated way to write code. Learn to write efficient code using indexing. You will not regret doing this.
In your case a 3D matrix might be best (if all output matrices are the same size), something like this (pseudocode):
P = 50;
mat = NaN(R,C,P);
for k = 1:P
mat(:,:,k) = your calculation here;
end
Otherwise a cell array will do the job as well.

Más respuestas (0)

Categorías

Más información sobre Get Started with MATLAB en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by