How to apply a cell array of function handles to a cell array of arguments

조회 수: 1 (최근 30일)
Jim
Jim 2016년 8월 2일
댓글: Jim 2016년 8월 2일
I have an MxN cell array fha of type conversion function handles (@double, @char, etc) that I'd like to apply element-by-element to an MxN cell array of strings x, but am struggling with the correct syntax. I've tried:
cellfun(@(s,t) s(t), fha, x, 'uni', 0)
which returns error in @(s,t)s(t) -- index exceeds matrix dimensions, and also:
cellfun(@(s,t) (s,t), fha, x, 'uni', 0)
but that's also flagged as incorrect -- possible unbalanced (, {, or [. Anyone got a clue?

답변 (1개)

Thorsten
Thorsten 2016년 8월 2일
Use nested cellfun calls
X = cellfun(@(fha_i) cellfun(fha_i, C, 'Uni', false), fha, 'Uni', false)
  댓글 수: 1
Jim
Jim 2016년 8월 2일
Sorry, that returns an MxN cell array of MxN cell arrays (interesting, though). But it's all good -- my 1st try worked once I gave it the right fha argument.

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

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by