Append a column to a cell variable if two conditions verify

3 ビュー (過去 30 日間)
Maria
Maria 2014 年 8 月 13 日
編集済み: Andrei Bobrov 2014 年 8 月 13 日
I have a cell variable with 7000 rows and 14 columns. There are no repeated rows. Example with only 9 columns:
A={1994 1440 5510 '4911' '025537101' 'AEP' 1440 0 'AEP'
1994 1587 5510 '4941' '030411102' 'AWK' 1587 556 'AWK'
1994 1837 5510 '4924' '001204106' 'AGLT' 1837 969 'AGLT'}
And a cell variable with 60000 rows (no duplicates) and 3 columns. Example:
c1 c2 c3
B={1994 'ABCR' 101101
1994 'AEP' 30504
1994 'ADD' 40402
1994 'AGLT' 40404
1994 'ASIN' 100101
1994 'AWK' 80801}
If the first and the last columns of A match with the first and second columns of B (c1 and c2), I would like to add a new column to A with the values from the last column of B (c3).
My new A would be:
A={1994 1440 5510 '4911' '025537101' 'AEP' 1440 0 'AEP' 30504
1994 1587 5510 '4941' '030411102' 'AWK' 1587 556 'AWK' 80801
1994 1837 5510 '4924' '001204106' 'AGLT' 1837 969 'AGLT' 40404}
Thanks
  2 件のコメント
Nathan
Nathan 2014 年 8 月 13 日
This is problematic and requires more information about what you would like to accomplish. does A or B contain doublicates? Do you want two additional columns period, but only write data into them if there is a match? Please be very specific so we can help.
Maria
Maria 2014 年 8 月 13 日
Nathan ok. I will edit my answer and be more specific. Thank you.

サインインしてコメントする。

採用された回答

Andrei Bobrov
Andrei Bobrov 2014 年 8 月 13 日
編集済み: Andrei Bobrov 2014 年 8 月 13 日
EDIT
[l1,i1] = ismember(A(:,end),B(:,2));
l2 = ismember([A{:,1}]',[B{:,1}]');
l3 = l1&l2;
A(l3,end+1) = B(i1(l3),3);
  2 件のコメント
Maria
Maria 2014 年 8 月 13 日
Andrei it gives this error: Subscripted assignment dimension mismatch. But I will edit my question now and make it more undertandable. Thank you
Andrei Bobrov
Andrei Bobrov 2014 年 8 月 13 日
編集済み: Andrei Bobrov 2014 年 8 月 13 日
corrected

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by