While loop shows the result of the previous run

10 views (last 30 days)
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

Accepted Answer

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

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!