Effacer les filtres
Effacer les filtres

How to gracefully generate an all-one cell array?

1 vue (au cours des 30 derniers jours)
埃博拉酱
埃博拉酱 le 29 Oct 2019
Commenté : Alex Mcaulley le 29 Oct 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 commentaires
Alex Mcaulley
Alex Mcaulley le 29 Oct 2019
Rik
Rik le 29 Oct 2019
@Alex, it looks to me like this is the desired result, so I would suggest moving your comment to the answer section.

Connectez-vous pour commenter.

Réponse acceptée

Alex Mcaulley
Alex Mcaulley le 29 Oct 2019
Modifié(e) : Alex Mcaulley le 29 Oct 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 commentaires
Rik
Rik le 29 Oct 2019
Note that to actually use this function, you should use varargin{:} in your call to ones.
Alex Mcaulley
Alex Mcaulley le 29 Oct 2019
That's true @Rik ;)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Produits


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by