Effacer les filtres
Effacer les filtres

workspace & LOOP FOR

2 vues (au cours des 30 derniers jours)
Marwen Tarhouni
Marwen Tarhouni le 30 Déc 2016
Modifié(e) : Stephen23 le 30 Déc 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

Réponse acceptée

Stephen23
Stephen23 le 30 Déc 2016
Modifié(e) : Stephen23 le 30 Déc 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.

Plus de réponses (0)

Catégories

En savoir plus sur Get Started with MATLAB dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by