How to find minimum value from loop using if function iteration?
    6 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Anom Sulardi
 el 29 de Jun. de 2020
  
    
    
    
    
    Comentada: Stephen23
      
      
 el 1 de Jul. de 2020
            I have a=6.5, I would like to define "if function" inside the "for loop", for i=1:10, it will do the loop imin < a < imax, and if the "if function" is correct, I would like to use the b= imin (in which the a function is correct). 
My expectation toward the code is b=6. Since the 6.5 is in between number for loop 6 and 7. And I want to use 6 (imin where the a is in correct statemen for if function)
How do I code that in matlab?
a=6.5;
for i=1:10
    imin=i;
    imax=imin+1
    if imin<a<imax
        b=imin;
    end
    if imax==10;
    end
end
2 comentarios
Respuesta aceptada
Más respuestas (1)
  bharath pro
      
 el 29 de Jun. de 2020
        
      Editada: bharath pro
      
 el 29 de Jun. de 2020
  
      Instead of using imin<a<imax, try using an intersection of two commands for checking less than and greater than seperatly.
a=6.5;
for i=1:10
    imin=i;
    imax=imin+1
    if (imin<a)&&(a<imax)
        b=imin;
    end
    if imax==10;
    end
end
This will give the output as 6
Ver también
Categorías
				Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


