How to find the nearest matrix between two matrices?
Mostra commenti meno recenti
Find the nearest row matching between matrix.
I have a matrix
A = [2013 03 17 1 6 0]; % 1x6 double
I have another matrix
B = [2013 3 17 0 5 1.012; 2013 3 17 1 6 20.47]; % 4x6 double
I want to find the index of the nearest matrix A in B.
Can anyone please help?
Any help will be greatly appriciated.
Risposta accettata
Più risposte (1)
Abderrahim. B
il 18 Lug 2022
Modificato: Abderrahim. B
il 18 Lug 2022
clear
A = [2013,3,17,1,6,0]; % 1x6 double
B = [2013,3,17,0,5,1.012; 2013,3,17,1,6,20.47]; % 4x6 double
A = datetime(A) ;
B = datetime(B) ;
minSize_B = max(size(B)) ;
nearestAB = [] ;
for ii = 1:minSize_B
nearestAB = [nearestAB abs(A - B(ii))] ;
end
[~, nearestB_indx] = min(nearestAB) % Means, the 4th row in B
nearestB = B(nearestB_indx)
5 Commenti
MP
il 18 Lug 2022
MP
il 18 Lug 2022
Abderrahim. B
il 18 Lug 2022
Thought vectors are numeric arrays not date time ..
Edited my answer, check it out.
MP
il 19 Lug 2022
Categorie
Scopri di più su Dates and Time in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!