필터 지우기
필터 지우기

Assigning matrix to cells

조회 수: 5 (최근 30일)
Di Zhu
Di Zhu 2016년 5월 20일
댓글: Di Zhu 2016년 5월 20일
Hello! I have preallocated the variable S with:S = cell(3,2); I want to assign the matrix [0 0 0] to each cell element, like this:
[0 0 0] [0 0 0]
[0 0 0] [0 0 0]
[0 0 0] [0 0 0]
I know that num2cell(zeros(3,2)) will give me
[0] [0]
[0] [0]
[0] [0]
Does anybody know if there is any way I can do this without using a for loop to assign [0 0 0] to each of the cell element? Thanks!

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2016년 5월 20일
편집: Azzi Abdelmalek 2016년 5월 20일
cellfun(@(x) zeros(1,3),cell(3,2),'un',0)
Or
mat2cell(zeros(3,2*3),ones(1,3),3*ones(1,2))
  댓글 수: 1
Di Zhu
Di Zhu 2016년 5월 20일
Thank you!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by