필터 지우기
필터 지우기

How to populate a cell in a cell array with an array

조회 수: 3 (최근 30일)
Gideon Maasz
Gideon Maasz 2018년 8월 20일
답변: Rik 2018년 8월 20일
I have tried to find a suitable solution on the pages but cant seem to find any. I have a cell array of m x n dimensions and I have arrays being created of 2x1 dimensions and would like to insert each array into a different cell of the cell array.
a=cell(4x5)
for i = 1:5
for j = 1:4
b = array which was calculated as 2x1 array
a(j,i) = b
end
end
I can't seem to get this right. I keep getting the following error:
Assignment has more non-singleton rhs dimensions than non-singleton subscripts
Help will be appreciated.

채택된 답변

Rik
Rik 2018년 8월 20일
The reason for this error is the way cells work: you can access the contents with curly brackets, or the cell as a container with round brackets. Also, using i or j can cause problems when they might be interpreted as the imaginary unit.
a=cell(4,5)
for ind2 = 1:size(a,2)
for ind1 = 1:size(a,1)
b = array which was calculated as 2x1 array
a{ind1,ind2} = b
end
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by