How to save value of find function?
    2 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    laith Farhan
 el 3 de Ag. de 2018
  
    
    
    
    
    Comentada: laith Farhan
 el 3 de Ag. de 2018
            Dear all, How to save the value of x vector in de vector based on find function?
expected results is : de = [1 4 7 3 10 6 90 1.1 80];
x=[ 1 4 7 3 10 6 0 90 1.1 80]; for i=1:10 de = find(x > 0); end
Many thanks...
0 comentarios
Respuesta aceptada
  Stephen23
      
      
 el 3 de Ag. de 2018
        
      Editada: Stephen23
      
      
 el 3 de Ag. de 2018
  
      Your loop is superfluous, get rid of it. Simpler with logical indexing:
>> x = [1,4,7,3,10,6,0,90,1.1,80];
>> de = x(x>0)
de =
  1  4  7  3  10  6  90  1.1  80
6 comentarios
  Stephen23
      
      
 el 3 de Ag. de 2018
				
      Editada: Stephen23
      
      
 el 3 de Ag. de 2018
  
			"expected results is: [ 0 0 0 4 0 0 7 8 0 10];"
>> x = [1,4,7,3,10,6,0,90,1.1,80];
>> (1:numel(x)) .* (x<=0)
ans =
  0  0  0  4  0  0  7  8  0  10
If your professor insists that you use a pointless find, then something like this perhaps:
>> idx = find(x<=0);
>> vec = zeros(size(x));
>> vec(idx) = idx
vec =
  0  0  0  4  0  0  7  8  0  10
Más respuestas (0)
Ver también
Categorías
				Más información sobre Logical 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!


