How to gracefully generate an all-one cell array?
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
Rik
2019-10-29
@Alex, it looks to me like this is the desired result, so I would suggest moving your comment to the answer section.
采纳的回答
Alex Mcaulley
2019-10-29
编辑:Alex Mcaulley
2019-10-29
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 个评论
Rik
2019-10-29
Note that to actually use this function, you should use varargin{:} in your call to ones.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!