While loop shows the result of the previous run

12 Ansichten (letzte 30 Tage)
Hessa Althallab
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

Akzeptierte Antwort

Torsten
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.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Produkte


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by