While loop shows the result of the previous run
10 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
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.
0 Comments
More Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!