While loop shows the result of the previous run
12 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hessa Althallab
am 18 Nov. 2023
Bearbeitet: Hessa Althallab
am 19 Nov. 2023
So I'm currently working on a code for rank order clustering method, the issue I have is that I have to calculate once for the rows reorder them to descend then calculate the columns and reorder them to descent again. on my last run on the while loop the rows had to be reordered but the columns didnt have to, so the while loop was broken but it shows the matrix that was in the previous run. I've attached the code
0 Kommentare
Akzeptierte Antwort
Torsten
am 18 Nov. 2023
% Check if there's any change in the matrix positions
previous_matrix = matrix; % Store the previous matrix
% Check for convergence
if isequal(previous_matrix, matrix)
change = false;
end
If you set previous_matrix to matrix before you check if they are equal, then (since they are set before to be equal) "change" will become "false" immediately after the first loop through the "while" statement.
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!