how to append matrix value from lookup list

1 vue (au cours des 30 derniers jours)
BeeTiaw
BeeTiaw le 23 Nov 2016
Commenté : BeeTiaw le 23 Nov 2016
I have the following matrix A =
0 34.5 10 3 22.753 8.9632
0 34.5 10 7 22.753 8.9632
0 68.9 10 3 22.753 8.9632
0 68.9 10 7 22.753 8.9632
0 137.9 10 3 22.753 8.9632
0 137.9 10 7 22.753 8.9632
0 206.8 10 3 22.753 8.9632
0 206.8 10 7 22.753 8.9632
0 275.8 10 3 22.753 8.9632
0 275.8 10 7 22.753 8.9632
10 34.5 10 3 22.753 8.9632
10 34.5 10 7 22.753 8.9632
10 68.9 10 3 22.753 8.9632
10 68.9 10 7 22.753 8.9632
10 137.9 10 3 22.753 8.9632
10 137.9 10 7 22.753 8.9632
10 206.8 10 3 22.753 8.9632
10 206.8 10 7 22.753 8.9632
10 275.8 10 3 22.753 8.9632
10 275.8 10 7 22.753 8.9632
I want to insert a new column to the right containing values from the following lookup list
B =
0 34.5 328.5
0 68.9 415.6
0 137.9 589.6
0 206.8 727.9
0 275.8 856.1
10 34.5 307.4
10 68.9 362
10 137.9 541.6
10 206.8 695.6
10 275.8 856.1
20 34.5 263.9
20 68.9 337.5
20 137.9 503.8
20 206.8 635.3
20 275.8 749
30 34.5 224.9
30 68.9 297.4
30 137.9 437.9
30 206.8 573.9
30 275.8 673.1
The values in the new columns in A is based on the lookup list of B.
Manually, I would expect something like this
C =
0 34.5 10 3 22.753 8.9632 328.5
0 34.5 10 7 22.753 8.9632 328.5
0 68.9 10 3 22.753 8.9632 415.6
0 68.9 10 7 22.753 8.9632 415.6
0 137.9 10 3 22.753 8.9632 589.6
0 137.9 10 7 22.753 8.9632 589.6
0 206.8 10 3 22.753 8.9632 727.9
0 206.8 10 7 22.753 8.9632 727.9
etc...
Notice the last column of C is based on the values in A column 1 and 2 which is matched with the lookup list in B column 1 and 2.
Can anyone help me.
  2 commentaires
Jan
Jan le 23 Nov 2016
Modifié(e) : Jan le 23 Nov 2016
So actually only the 2 first columns of A matter, right? How is the lookup table used: choose the nearest 2 elements, choose at exact match (what is dangerous for floating point values), linear interpolation? What should happen to the elements, which are not found in B?
BeeTiaw
BeeTiaw le 23 Nov 2016
Modifié(e) : BeeTiaw le 23 Nov 2016
Hi Simon,
Correct. in each row, the first two columns of A has to be exactly match with the first two columns in B.
If the condition satisfies, the value will be taken from the third column of B.

Connectez-vous pour commenter.

Réponse acceptée

Jan
Jan le 23 Nov 2016
Modifié(e) : Jan le 23 Nov 2016
Perhaps:
[LiA, LocB] = ismember(A(:, 1:2), B(:, 1:2), 'rows');
C = [A, B(LocB, 3)]
Use ismembertol to consider numerical rounding errors.
  1 commentaire
BeeTiaw
BeeTiaw le 23 Nov 2016
Thanks you! This is exactly what I expect.
appreciate your time.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Tables 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