필터 지우기
필터 지우기

How to nest a cell array with existing cell array

조회 수: 20 (최근 30일)
kowshik Thopalli
kowshik Thopalli 2017년 1월 25일
댓글: Jan 2017년 1월 26일
Hi, I have a cell array Cells which is 1 x 190, and each cell is again a 1 x 20 cell array. Now for each cell in this 1 x 20 array I have to add two more cells which contain matrices. I tried doing Cells{1,1}{1,1}{1,1}=mymatrix; Cells{1,1}{1,1}{1,2}=mymatrix2; But I get an error Cell contents assignment to a non-cell array object. I am doing this in a loop like
for i =1:190
for j=1:20
Cells{1,i}{1,j}{1,1}=mymatrix;
Cells{1,i}{1,j}{1,2}=mymatrix2;
end
end
How can I also speed this up. Thanks

채택된 답변

Jan
Jan 2017년 1월 25일
편집: Jan 2017년 1월 26일
Cells = cell(1, 190);
for i1 = 1:190
SubCell = cell(1, 20);
for i2 = 1:20
SubCell{i2} = {mymatrix, mymatrix2};
end
Cells{i1} = SubCell;
end
  댓글 수: 2
kowshik Thopalli
kowshik Thopalli 2017년 1월 25일
Should It have been Cells{1,i1}=Subcell, Right?
Jan
Jan 2017년 1월 26일
You are right, a typo. Fixed now. Cells{i1} is a tick faster than Cell{1, i1} with the same result.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by