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 Comments

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

Sign in to comment.

 Accepted Answer

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 Comments

Note that to actually use this function, you should use varargin{:} in your call to ones.
That's true @Rik ;)

Sign in to comment.

More Answers (0)

Categories

Find more on Environment and Settings in Help Center and File Exchange

Products

Release

R2019b

Asked:

on 29 Oct 2019

Commented:

on 29 Oct 2019

Community Treasure Hunt

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

Start Hunting!