필터 지우기
필터 지우기

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
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 CenterFile Exchange에서 Loops 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