if statement on cell

조회 수: 1 (최근 30일)
Grigorios Kyritsakas
Grigorios Kyritsakas 2018년 7월 19일
댓글: Grigorios Kyritsakas 2018년 7월 19일
Hi,
I have a matrix A with 3 columns. The first column contains letters (specific reference numbers) and the other two columns contain numbers (values). I also have a big table B that contains also the first column of the matrix A but its length is bigger than A's as some reference numbers are repeated. I want to add two extra columns in table B where for each reference number I get the corresponding to the reference number values of the matrix A. I tried to use the if function but it didn't work (as reference numbers are cells) and isequal is not working as the first column in A has less rows than the columns of table B. Can anyone help me with this?
  댓글 수: 3
Guillaume
Guillaume 2018년 7월 19일
Or if the matrices were converted to tables, which sound better suited for what they contain, a single call to join would do the job.
But yes, an example of the inputs is required, particularly since matrices cannot contain both text and numbers, so it's unknown what A and B actually are.
Grigorios Kyritsakas
Grigorios Kyritsakas 2018년 7월 19일
Hello and thanks to both of you.
A is a table not a matrix - apologies for that mistake. Let's say that A =
5×3 table
NODEID AW2 AP2
____________ ______ ______
'000 440 01' 27.95 48.78
'000 480 01' 67.09 31.11
'000 656 01' 89.25 41.11
'001 479 08' 65.91 35.3
'001 479 13' 65.5 35.04
B =
9×4 table
Sample ID GL D
__________ ____________ ______ ______
7.4602e+06 '000 440 01' 54.1 131.9
1.0423e+07 '000 440 01' 54.1 131.9
1.0451e+07 '000 440 01' 54.1 100.22
6.6269e+06 '000 480 01' 49.1 17.475
8.0283e+06 '000 656 01' 6 505.4
1.0383e+07 '000 656 01' 6 505.4
8.373e+06 '001 479 08' 44.576 34.732
7.7677e+06 '001 479 13' 44.84 19.308
6.9789e+06 '001 479 18' 45.58 33.286
ID column in table B contains the reference numbers that are also included in NODEID in table one. I want the numbers of the columns AW2 and AP2 of table to be added as an extra column in the corresponding reference number in table B.
Thanks again

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

채택된 답변

Guillaume
Guillaume 2018년 7월 19일
편집: Guillaume 2018년 7월 19일
Since your inputs are tables, it's trivial to merge the two tables as you want:
C = outerjoin(B, A, 'LeftKeys', 'ID', 'RightKeys', 'NODEID', 'MergeKeys', true)
Possibly, you want an innerjoin instead of an outerjoin if you don't want to retain the rows of B that have no match in A.
  댓글 수: 1
Grigorios Kyritsakas
Grigorios Kyritsakas 2018년 7월 19일
Perfect! That worked!
Thank you very much for your help!

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

추가 답변 (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