Create a Cell Array of Vectors populated with ones

조회 수: 16 (최근 30일)
Leonardo Venturelli
Leonardo Venturelli 2019년 5월 15일
편집: Leonardo Venturelli 2019년 5월 23일
Hi all,
I 'd like to create a cell array made of x columns and y rows (in my case 10 and 3, respectively), where each x,y position contains a vector of 1x200 NaN. I'd like to find something smarter and nicer than just something like this:
res={nan(1,200) nan(1,200) nan(1,200) nan(1,200) nan(1,200) nan(1,200) nan(1,200) nan(1,200) nan(1,200) nan(1,200) ;nan(1,200) nan(1,200) nan(1,200) nan(1,200) nan(1,200) nan(1,200) nan(1,200) nan(1,200) nan(1,200) nan(1,200); nan(1,200) nan(1,200) nan(1,200) nan(1,200) nan(1,200) nan(1,200) nan(1,200) nan(1,200) nan(1,200) nan(1,200)};
Thank you so much to the community.
Leonardo
  댓글 수: 1
Guillaume
Guillaume 2019년 5월 15일
If all the vectors in the cell array are the same size, why not use a matrix instead of a cell array. It will make all subsequent operations much easier.
I.e. create a 10x3x200 matrix instead:
res = nan(10, 3, 200);

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

채택된 답변

Jos (10584)
Jos (10584) 2019년 5월 15일
repmat also works for cell arrays
C = repmat({nan(1, 200)}, 10, 3)
  댓글 수: 1
Leonardo Venturelli
Leonardo Venturelli 2019년 5월 15일
편집: Leonardo Venturelli 2019년 5월 23일
Thank you so much Jos,
I hadn't tried the repmat function to solve this, but it actually works perfectly.

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by