# How to iterate through a Multi-Dimensional Cell array?

21 ビュー (過去 30 日間)
DEEPAK PHCSFI17041149 2017 年 11 月 27 日
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 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!
##### 1 件のコメント表示非表示 なし
DEEPAK PHCSFI17041149 2017 年 12 月 13 日
Thanks very much Sonam

サインインしてコメントする。

### カテゴリ

Find more on Matrix Indexing in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by