Filter löschen
Filter löschen

Incrementing value in an executing loop

1 Ansicht (letzte 30 Tage)
FIR
FIR am 26 Jul. 2012
I have a matrix A =
12 13 6 7
5 4 5 1
2 2 11 13
7 1 3 6
and the following code:
%%%%(th=threshold)
th=4
for i=1:4
for j=1:4
if A(i,j) < th
A(i,j) = 0;
G=nnz(A);
end
end
end
I have calculated nnz where I get G=11,for threshold 4.
Now I want to automatically increment the th value such that if G is less than 5 the loop should termainate, and find the value of th when the loop terminated.
  1 Kommentar
Albert Yam
Albert Yam am 26 Jul. 2012
Please reword your question. I don't understand what you are asking.
From what I gather,
  • when G == 11, you want th = 8 ?
  • when G <= 5 , stop the loop?
  • but if you stop the loop what does increasing 'th' do?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

venkat vasu
venkat vasu am 27 Jul. 2012
Bearbeitet: Andrei Bobrov am 27 Jul. 2012
th=4
for i=1:4
for j=1:4
if A(i,j) < th
A(i,j) = 0;
G=nnz(A);
if G<5
th=th+1;
break;
end
end
end
end
this may help you...

Weitere Antworten (1)

Andrei Bobrov
Andrei Bobrov am 27 Jul. 2012
G=5;
th = 0;
while sum(A(:) >= th) >= G
th = th + 1;
end

Kategorien

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

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by