how to compress and delete the same values in vector?
    5 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Shubham Mohan Tatpalliwar
 el 29 de Nov. de 2018
  
    
    
    
    
    Editada: madhan ravi
      
      
 el 29 de Nov. de 2018
            i have two vector in which the values are repeated.
in first i want to delete the repeated values such as
A=[1,2,3,3,3,4,5,6,6,7,7,8,9]
Awant=[1,2,3,4,5,6,7,8,9]
and in the second vector i want the repeated values to be counted only once and the others are zero
B=[1,2,3,3,3,4,4,5,5,6,6,7,8,9]
Bwant=[1,2,0,0,3,0,4,0,5,0,6,7,8,9]
or else a index matrix will also be good
Bwant=[1,1,0,0,1,0,1,0,1,0,1,1,1,1]
Thanks in advance
0 comentarios
Respuesta aceptada
  madhan ravi
      
      
 el 29 de Nov. de 2018
        
      Editada: madhan ravi
      
      
 el 29 de Nov. de 2018
  
      >> A=[1,2,3,3,3,4,5,6,6,7,7,8,9];
   Awant=unique(A)
   B=[1,2,3,3,3,4,4,5,5,6,6,7,8,9];
   [~,c,~]=unique(B,'last');
   B1=zeros(1,numel(B));
   B1(c)=B(c);
   B1(~c)=0
Awant =
     1     2     3     4     5     6     7     8     9
B1 =
  Columns 1 through 13
     1     2     0     0     3     0     4     0     5     0     6     7     8
  Column 14
     9
>> 
0 comentarios
Más respuestas (0)
Ver también
Categorías
				Más información sobre Assembly 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!

