필터 지우기
필터 지우기

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