I have a cell array defined as A = cell(i,8)
;
say i = 4
. now i am trying to fill up the 4 x 8 cell array with a function present inside the loop.
Say,
A = cell(i,8);
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) - 4 x 8 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.
Firs thing A{i,index} = zeros(C{i}, D{i}, E{i});
not correct since zero()
not accept array as paramerts.
This code will solve your problem
i=4;
A = cell(i,8);
C{i} = {10,10,10,10};
D{i} = {[13] [13] [13] [13]};
E{i} = {[62] [91] [71] [89]};
for j=1:8
for index=1:4
A{index,j} = zeros(cell2mat(C{i}(index)), cell2mat(D{i}(index)), cell2mat(E{i}(index)));
end
end
This is the output
A =
4×8 cell array
Columns 1 through 6
[10×13×62 double] [10×13×62 double] [10×13×62 double] [10×13×62 double] [10×13×62 double] [10×13×62 double]
[10×13×91 double] [10×13×91 double] [10×13×91 double] [10×13×91 double] [10×13×91 double] [10×13×91 double]
[10×13×71 double] [10×13×71 double] [10×13×71 double] [10×13×71 double] [10×13×71 double] [10×13×71 double]
[10×13×89 double] [10×13×89 double] [10×13×89 double] [10×13×89 double] [10×13×89 double] [10×13×89 double]
Columns 7 through 8
[10×13×62 double] [10×13×62 double]
[10×13×91 double] [10×13×91 double]
[10×13×71 double] [10×13×71 double]
[10×13×89 double] [10×13×89 double]