Clear Filters
Clear Filters

How can i stop loop if all matrix elements are similar?

1 view (last 30 days)
The matrix is modified in each iteration. When all elements of matrix are similar i want to stop the iteration. For example i tried by using codes shown below but it doesnt work. May you help me for solving this problem?
iteration=0;
np=10;
W=zeros(np,1);
while iteration<1000
Wupdate %The sub-script that modify the matrix
if np*W(1)==sum(W)
iteration=10000
end
end

Accepted Answer

Matt J
Matt J on 31 Aug 2017
Edited: Matt J on 31 Aug 2017
if max(W(:))-min(W(:))<=tolerance
break;
end

More Answers (0)

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!