Effacer les filtres
Effacer les filtres

Find the 3D components-based row of an array that most closely matchs a given vector

3 vues (au cours des 30 derniers jours)
Hello everyone
I'm currently trying to find the most efficient way to find which three components-based row of an array is the closest one to a given 3D vector. For example, let's imagine that I have an array, aa, and a vector, bb, like the following ones:
aa=[1.1 1.4 1.7; 1.3 1.1 1.2; 1.8 1.0 1.7];
bb=[1.3 1.3 1.3];
If my vector bb were exactly equal to one of the rows of the aa array I would do something like:
but in my case, I probably have to base it on the vector module hosted in each row of the aa array.
Does anyone have any suggestions on how to efficiently perform this task considering that my bb vector changes in a for loop?

Réponses (1)

Paul le 15 Fév 2024
I think the specific solution would depend on the figure of merit for defining "closeness" of two vectors.
For example, if the figure of merit is the 2-norm of the difference, then we can do
aa=[1.1 1.4 1.7; 1.3 1.1 1.2; 1.8 1.0 1.7]
aa = 3×3
1.1000 1.4000 1.7000 1.3000 1.1000 1.2000 1.8000 1.0000 1.7000
bb=[1.3 1.3 1.3];
v = vecnorm(aa - bb,2,2) % for clarity
v = 3×1
0.4583 0.2236 0.7071
[~,ii] = min(v);
ans = 1×3
1.3000 1.1000 1.2000


En savoir plus sur Multidimensional Arrays dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by