How to iterate through a Multi-Dimensional Cell array?

조회 수: 5 (최근 30일)
DEEPAK PHCSFI17041149
DEEPAK PHCSFI17041149 2017년 11월 27일
댓글: DEEPAK PHCSFI17041149 2017년 12월 13일
I have a cell array defined as
A = cell(i,8);
say i = 4. now i am trying to fill up the 4x8 cell array with a function present inside the loop. Say,
for index=1:8
A{i,index} = zeros(C{i}, D{i}, E{i});
end
where, the values of C{i}, D{i}, E{i} are
C{i} = [10] [10] [10] [10]
D{I} = [13] [13] [13] [13]
E{I} = [62] [91] [71] [89]
And the contents of the cell are obviously zeros, since i used zeros() but i need this step for some further processing.
Now, i should get the Value of A(Cell array) - 4x8 Dimension like below,
10x13x62 double10x13x62 double 10x13x62 double 10x13x62 double 10x13x62 double 10x13x62 double 10x13x62 double 10x13x62 double
10x13x91 double 10x13x91 double 10x13x91 double 10x13x91 double 10x13x91 double 10x13x91 double 10x13x91 double 10x13x91 double
10x13x71 double 10x13x71 double 10x13x71 double 10x13x71 double 10x13x71 double 10x13x71 double 10x13x71 double 10x13x71 double
10x13x89 double 10x13x89 double 10x13x89 double 10x13x89 double 10x13x89 double 10x13x89 double 10x13x89 double 10x13x89 double
Instead i am getting the output like,
[] [] [] [] [] [] [] []
[] [] [] [] [] [] [] []
[] [] [] [] [] [] [] []
10x13x89 double 10x13x89 double 10x13x89 double 10x13x89 double 10x13x89 double 10x13x89 double 10x13x89 double 10x13x89 double
I hope i am missing some simple logic behind the loop and the Cell array, is my initialization of the cell array and the loop is correct? if not, please suggest me to find a solution like i mentioned above.
Thanks.

채택된 답변

Sonam Gupta
Sonam Gupta 2017년 12월 6일
In the output that you have shown above, only 4th row is getting updated because value of i is always 4. Another loop is needed to change the value of i from 1 to i as below:
i = 4;
A = cell(i,8);
C = {10 10 10 10};
D = {13 13 13 13};
E = {62 91 71 89};
for j = 1:i
for index=1:8
A{j,index} = zeros(C{j}, D{j}, E{j});
end
end
I hope this helps!

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by