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

Azzi Abdelmalek
Azzi Abdelmalek 2012년 8월 6일
what do you mean B is the index of A? and how C is related to A and B
zhang
zhang 2012년 8월 6일
C{i} = A{i}(B{i})

댓글을 달려면 로그인하십시오.

답변 (1개)

Honglei Chen
Honglei Chen 2012년 8월 6일
편집: Honglei Chen 2012년 8월 6일

0 개 추천

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

댓글 수: 2

Walter Roberson
Walter Roberson 2012년 8월 6일
zhang specifically asked "aside from cellfun"
Honglei Chen
Honglei Chen 2012년 8월 6일
편집: Honglei Chen 2012년 8월 6일
Added a solution with arrayfun, but I don't know if arrayfun is ok

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Data Types에 대해 자세히 알아보기

태그

질문:

2012년 8월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by