我想从一个简单的cell-array中提取一些特定的值,如下所示:
CellExample{1} = [1,54,2,3,4]
CellExample{2} = [1,4,1,92,9,0,2]
...还有一个额外的数组,它告诉我要从每个Cell元素中提取哪个元素。数组与单元格一样长:
ArrayExample = [2,4,...]基本上,我需要一个数组,上面写着:
Solution(1) = CellExample{1}(ArrayExample(1)) = 54
Solution(2) = CellExample{2}(ArrayExample(2)) = 92我曾想过使用细胞乐趣,但我仍然有一些问题,正确使用它,例如:
cellfun(@(x) x{:}(ArrayExample),CellExample,'UniformOutput',false)发布于 2016-02-10 13:59:25
以下是
Cell{1} = [1,54,2,3,4]
Cell{2} = [1,4,1,92,9,0,2]
cellfun(@(x) disp(x), Cell)等于循环。
for ii = 1:numel(Cell)
disp(Cell{ii})
end也就是说,cellfun()已经将每个单元格的content传递给匿名函数。
但是,由于您希望将一个arrayfun(),数字数组作为第二个输入传递给匿名函数,而且cellfun()只接受cell()输入,所以需要使用不解压缩单元格内容的。
就你而言:
arrayfun(@(c,pos) c{1}(pos), Cell, Array)它相当于:
for ii = 1:numel(Cell)
Cell{ii}(Array(ii))
endhttps://stackoverflow.com/questions/35317047
复制相似问题