how to append matrix value from lookup list

조회 수: 2 (최근 30일)
BeeTiaw
BeeTiaw 2016년 11월 23일
댓글: BeeTiaw 2016년 11월 23일
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
Jan
Jan 2016년 11월 23일
편집: Jan 2016년 11월 23일
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 2016년 11월 23일
편집: BeeTiaw 2016년 11월 23일
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.

댓글을 달려면 로그인하십시오.

채택된 답변

Jan
Jan 2016년 11월 23일
편집: Jan 2016년 11월 23일
Perhaps:
[LiA, LocB] = ismember(A(:, 1:2), B(:, 1:2), 'rows');
C = [A, B(LocB, 3)]
Use ismembertol to consider numerical rounding errors.
  댓글 수: 1
BeeTiaw
BeeTiaw 2016년 11월 23일
Thanks you! This is exactly what I expect.
appreciate your time.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by