grouping indices based on how close they are
    1 visualizzazione (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    
    Dawid Strzelczyk
 il 20 Nov 2020
  
    
    
    
    
    Risposto: Bruno Luong
      
      
 il 20 Nov 2020
            Hi
Lets say, I have an array with indices like this:
a = [11 12 13 25 26 55 56 57]
Is there a nice way of grouping them into three (in this case) groups based on how close they are?
a1 = [11 12 13]; a2 = [25 26]; a3 = [55 56 57]
Best,
Dawid 
0 Commenti
Risposta accettata
  Bruno Luong
      
      
 il 20 Nov 2020
        If your array is sorted
>> c = mat2cell(a,1,diff(find([true diff(a)>5 true]))); c{:}
ans =
    11    12    13
ans =
    25    26
ans =
    55    56    57
>> 
0 Commenti
Più risposte (0)
Vedere anche
Categorie
				Scopri di più su Matrix Indexing 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!

