How to gracefully generate an all-one cell array?

1 Ansicht (letzte 30 Tage)
埃博拉酱
埃博拉酱 am 29 Okt. 2019
Kommentiert: Alex Mcaulley am 29 Okt. 2019
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 Kommentare
Rik
Rik am 29 Okt. 2019
@Alex, it looks to me like this is the desired result, so I would suggest moving your comment to the answer section.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Alex Mcaulley
Alex Mcaulley am 29 Okt. 2019
Bearbeitet: Alex Mcaulley am 29 Okt. 2019
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 Kommentare
Rik
Rik am 29 Okt. 2019
Note that to actually use this function, you should use varargin{:} in your call to ones.
Alex Mcaulley
Alex Mcaulley am 29 Okt. 2019
That's true @Rik ;)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Just for fun finden Sie in Help Center und File Exchange

Produkte


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by