Finding the row index of the closest match to a row vector in an array
    7 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    
    Vinay Killamsetty
 il 27 Gen 2021
  
    
    
    
    
    Commentato: Vinay Killamsetty
 il 2 Feb 2021
            For example 
If we are having a row vector : [a b c]
and aray : 
[q w e r c; 
l v w e a
p w e r t];
Is there any way we can find the row index in the array closest to the defined row vector (matching 1st 3 column values or used defined columns)
0 Commenti
Risposta accettata
  Jan
      
      
 il 27 Gen 2021
        
      Modificato: Jan
      
      
 il 27 Gen 2021
  
      search = randi([1, 10], 1, 3);
data   = randi([1, 10], 10, 4);
dist = vecnorm(data(:, 1:numel(search)) - search, 2, 2);  % Auto-expand, >= R2016b
[~, match] = min(dist);
disp(search)
disp(data(match, :))
This uses the Euclidian norm to determine the distance. Maybe you want another norm.
Più risposte (0)
Vedere anche
Categorie
				Scopri di più su Data Types 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!

