在Matlab中构建一个具有不同数量零的单元数组

时间:2016-11-03 14:03:19

标签: arrays matlab vectorization

我想在第一列中有一个零的单元格数组,在下一个单元格中有2个零到n。

为此我尝试使用arrayfun:

index = 1:n;
a{index}=arrayfun(@(index) zeros(index,1),1);

我收到错误:

The right hand side of this assignment has too few values to satisfy
the left hand side.

我做错了什么?还试过交易。我想在没有for循环的情况下这样做。

1 个答案:

答案 0 :(得分:2)

这是使用mat2cell -

的矢量化方法
error: no type named ‘type’ in ‘class std::result_of<void (*(cv::Mat, std::reference_wrapper<cv::Mat>, int, int, cv::Mat))(const cv::_InputArray&, const cv::_OutputArray&, unsigned char, unsigned char, const cv::_InputArray&)>’

示例运行 -

mat2cell(zeros(n*(n+1)/2,1),1:n)