How to gracefully generate an all-one cell array?

1 回表示 (過去 30 日間)
埃博拉酱
埃博拉酱 2019 年 10 月 29 日
コメント済み: Alex Mcaulley 2019 年 10 月 29 日
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 Mcaulley
Alex Mcaulley 2019 年 10 月 29 日
Rik
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
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
Rik 2019 年 10 月 29 日
Note that to actually use this function, you should use varargin{:} in your call to ones.
Alex Mcaulley
Alex Mcaulley 2019 年 10 月 29 日
That's true @Rik ;)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by