フィルターのクリア

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 Center および File ExchangeGet Started with MATLAB についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by