Pass elements to a different cell array given a specific condition
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
dpb
el 17 de Mayo de 2014
Editada: dpb
el 17 de Mayo de 2014
>> 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 comentarios
Ver también
Categorías
Más información sobre Financial Toolbox en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!