Pass elements to a different cell array given a specific condition
조회 수: 1 (최근 30일)
이전 댓글 표시
I am working with matlab, and I have two different cell arrays with several elements. A primary and a secondary one. There is one element that is common in both cells, although the number of rows and order is not equal. What I would like is for X extra elements from the secondary cell to ‘pass’ to the primary one every time a condition is verified. The condition would be if column Y (from primary cell) and Z (from secondary cell) match. For instance:
Primary cell array:
ABC 970508 …
FED 970524 …
BAC 970601 …
IGH 970606 …
Secondary cell array
IGH FINANCE BANK1
FED HEALTH PILLS
ABC FINANCE BANK3
What I would like to get in the ‘new’ primary cell array:
ABC 970508 FINANCE BANK3
FED 970524 HEALTH PILLS
BAC 970601 …
IGH 970606 FINANCE BANK1
Can anyone help me? Thank you very much.
댓글 수: 0
답변 (1개)
dpb
2014년 5월 17일
편집: dpb
2014년 5월 17일
>> a={'ABC' '970508';'FED' '970524';'BAC' '970601';'IGH' '970606'};
>> b={'IGH' 'FINANCE BANK1';'FED' 'HEALTH PILLS';'ABC' 'FINANCE BANK3'};
>> [ia,ib]=ismember(a(:,1),b(:,1));
>> a(ia,end+1)=b(ib(ib>0),2)
a =
'ABC' '970508' 'FINANCE BANK3'
'FED' '970524' 'HEALTH PILLS'
'BAC' '970601' []
'IGH' '970606' 'FINANCE BANK1'
>>
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Financial Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!