choosing unique elements in the order that they appear in a column of a cell vector
    4 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    
 Dear all,
I have the following cell matrix
 Out={    
'MN'    'AER_KL1'           'Bdrerv_1'  
'MN'     'AER_KL1'         'Bdrerv_1'  
'MN'     'AER_KL1'       'Bdrerv_1'  
'MN'    'AER_KL1'       'Bdrerv_1'  
'MN'     'AER_KL1'         'ksitre +2er'     
'MN'      'AER_KL1'       'ksitre +2er'     
'MN'  'AER_KL1'           'ksitre +2er'     
'MN'   'AER_KL1'          'ksitre +2er'        
'MN'  'AER_KL1'           'ksitre +2er'     
'MN'  'AER_KL1'         'ksitre +2er'     
'MN'   'AER_KL1'           'ksitre +2er'     
'MN'     'AER_KL1'          'eorftr>2'     
'MN'   'AER_KL1'           'eorftr>2'     
'MN'    '100_pr'           'se 34'  
'MN'     '100_pr'            'se 34'  
'MN'     '100_pr'            'se 34'  
'MN'    '100_pr'           'se 34'  
'MN'     '100_pr'           'se 34'      
'MN'      '100_pr'          'se 34'  
'MN'  '100_pr'           'se 34'    
'MN'   '100_pr'           'fjgitow f12'   
'MN'  '100_pr'           'fjgitow f12'     
'MN'  '100_pr'           'fjgitow f12'     
'MN'   '100_pr'           'fjgitow f12'      
'MN'     '100_pr'           'fjgitow f12'     
'MN'   '100_pr'           '344 edd'   }
I want to simplify this matrix so as to have the following specific structure
 'MN'    'AER_KL1'           'Bdrerv_1'  
'MN'  'AER_KL1'           'ksitre +2er'     
'MN'     'AER_KL1'          'eorftr>2'     
'MN'    '100_pr'           'se 34'  
'MN'  '100_pr'           'fjgitow f12'    
'MN'   '100_pr'           '344 edd'   }
As you can see I want to select the unique elements from the last column in the order that appear in “out” and construct the above simplified matrix.
IS there any quick/efficient code for doing this?
 The above matrix is an example
My original data set is of dimension 25000 by 4. So a general code for doing this is greatly appreciated
0 Commenti
Risposta accettata
  Jan
      
      
 il 30 Gen 2013
        If you have a modern version of Matlab, the unique command can be controlled by teh 'first' flag to reply the first index.
4 Commenti
  Sean de Wolski
      
      
 il 30 Gen 2013
				Well 'first' returns the first index, not necessarily 'stable' order; consider:
>> [uv,idx] = unique([3;2;3;1],'first')
Più risposte (1)
  Thorsten
      
      
 il 30 Gen 2013
        
      Modificato: Thorsten
      
      
 il 30 Gen 2013
  
      You can to it "by feet"
 unique_rows = 1;
 for i = 2:size(Out, 1)
   equals_row = 0;
   for j = 1:numel(unique_rows)
     equal_row = strcmp(Out{i, 3}, Out{unique_rows(j), 3});
     if equal_row, break, end
   end
   if ~equal_row, unique_rows(end+1) = i, end
 end
 Out_simple = Out(unique_rows, :)
0 Commenti
Vedere anche
Categorie
				Scopri di più su Other Formats 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!




