workspace & LOOP FOR

2 次查看(过去 30 天)
Marwen Tarhouni
Marwen Tarhouni 2016-12-30
编辑: Stephen23 2016-12-30
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

采纳的回答

Stephen23
Stephen23 2016-12-30
编辑:Stephen23 2016-12-30
"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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by