필터 지우기
필터 지우기

Append a column to a cell variable if two conditions verify

조회 수: 4 (최근 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 CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by