how to use while loop
    4 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    
i have written a code to find the mod and dividend values of an image.if i
use while loop its getting executed continuously with out stop..can any one
help me where i am wrong...Thanks in advance
share = [250 250 ]
k=ceil(log(250)/log(5));
[r,c]=size(share)
for m= 1:r
        for n = 1:c
        while  share(m,n)>=0
            digits=mod(share(m,n),5)
             share(m,n)=ceil(share(m,n)/5)
        end
    end
end
0 Commenti
Risposte (2)
  Walter Roberson
      
      
 il 23 Nov 2012
        Suppose share(m,n) was 1. Then 1/5 is 0.2 and ceil(0.2) is 1. Opps, infinite loop!
0 Commenti
  Matt Fig
      
      
 il 23 Nov 2012
        
      Modificato: Matt Fig
      
      
 il 23 Nov 2012
  
      Think about this for a second: share(m,n) is initially positive. Then you repeatedly divide it by 5 in the inner while loop. How do you expect to ever get share(m,n) to be negative simply by dividing it by 5? But that is exactly what is needed to break that inner while loop....
For all x > 0: x/5 > 0, correct? So of course x/5 >= 0
0 Commenti
Vedere anche
Categorie
				Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


