How to gracefully generate an all-one cell array?

An all-one array can be gracefully generated by ones(...)
But what if I want an all-one cell array?
function Output=OnesInCell(varargin)
%This function should be the same as ones() except that each of the ones is packed into an individual cell.
end
For-loops are not graceful!

2 个评论

@Alex, it looks to me like this is the desired result, so I would suggest moving your comment to the answer section.

请先登录,再进行评论。

 采纳的回答

function Output=OnesInCell(varargin)
%This function should be the same as ones() except that each of the ones is packed into an individual cell.
Output = num2cell(ones(varargin));
end

2 个评论

Note that to actually use this function, you should use varargin{:} in your call to ones.

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Matrix Indexing 的更多信息

产品

版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by