how to process cell array

Hi guys
I have two cell arrays A, B.
A = {[1 -1 1], [2 3 6 5]};
B = {[2 1], [1 4]};
B is the index for A.
I'd like to have a certain function A(B) give me
C = {[-1 1], [2 5]}.
Aside from cellfun, Is there any other ways to do this?
Thanks,

2 commentaires

Azzi Abdelmalek
Azzi Abdelmalek le 6 Août 2012
what do you mean B is the index of A? and how C is related to A and B
zhang
zhang le 6 Août 2012
C{i} = A{i}(B{i})

Connectez-vous pour commenter.

Réponses (1)

Honglei Chen
Honglei Chen le 6 Août 2012
Modifié(e) : Honglei Chen le 6 Août 2012

0 votes

c = cellfun(@(a,b) a(b),A,B,'UniformOutput',false)
or
c = arrayfun(@(x)A{x}(B{x}),1:length(A),'UniformOutput',false)

2 commentaires

Walter Roberson
Walter Roberson le 6 Août 2012
zhang specifically asked "aside from cellfun"
Honglei Chen
Honglei Chen le 6 Août 2012
Modifié(e) : Honglei Chen le 6 Août 2012
Added a solution with arrayfun, but I don't know if arrayfun is ok

Connectez-vous pour commenter.

Catégories

En savoir plus sur Data Types dans Centre d'aide et File Exchange

Question posée :

le 6 Août 2012

Community Treasure Hunt

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

Start Hunting!

Translated by