special sorting
    6 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    
special sorting! i have the input vector of flags for different segments of the vector (flags are distributed randomly). how can i sort it to get the output? basically it reads from the beginning of the vector and labels each segment of the vector consecutively. there is no repetitive flags in the input vector for different segments.
input = [2 2, 5, 6 6 6, 1 1 1 1, 4, 3 3]
output= [1 1, 2, 3 3 3, 4 4 4 4, 5, 6 6]
2 Commenti
  Paulo Silva
      
 il 15 Ago 2011
				Sorry but I can't understand, you show the flags (input) and the output but no original vector to be sorted 
Risposta accettata
  Jan
      
      
 il 15 Ago 2011
        Do not use "input" as name of a variable, because it is a name of a built-in function.
in  = [2, 2, 5, 6, 6, 6, 1, 1, 1, 1, 4, 3, 3];
out = cumsum([1, diff(a) ~= 0]);
>> out = [1 1, 2, 3, 3, 3, 4, 4, 4, 4, 5, 6, 6]
2 Commenti
Più risposte (0)
Vedere anche
Categorie
				Scopri di più su Shifting and Sorting Matrices in Help Center e File Exchange
			
	Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


