if statement on cell

1 回表示 (過去 30 日間)
Grigorios Kyritsakas
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 Center および File ExchangeTables についてさらに検索

Translated by