Info

This question is closed. Reopen it to edit or answer.

A question in the light of 'Cell contents assignment to a non-cell array object' error

1 view (last 30 days)
Hello,
In my code, I am using the following constructs to create three cell arrays, using the following lines:
function result = creatematrixarray (narrays, arraysz)
result = cell(1, narrays);
for i = 1 : narrays
result{i} = zeros(arraysz);
end
end
Now, I am creating a sort of hierarchy in terms of an array A , an array B of arrays A, and another array C of arrays B. The reason for doing so is to numerically emulate a certain problem that I am researching on at the moment. So here is the code that I have written to create the hierarchy:
narrays = 3;
arraysz = [10,26];
array1 = creatematrixarray (narrays, arraysz);
narrays = 10;
arraysz = [3,10,26]; % this I believe would give me ten instances of the previous array
array2 = creatematrixarray (narrays, arraysz);
narrays = 10;
arraysz = [10,3,10,26]; % this I believe would again give me ten instances of the previous array
array3 = creatematrixarray (narrays, arraysz);
Now I am passing and returning array2 to and from a function, which is supposed to write to all the instances of array1 within array2, from columns 1-4, and all the 10 rows
And the syntax I am using to do this within the function is something like this:
for j = 1:10
for k = 1:3 % for array 1 dimensions
% for data
for i=1:10
switch i
case 1
array2{j} {k}(i,i) = i * 10;
And precisely at the last line I get the 'Cell contents assignment to a non-cell array object' error. I am not sure about where I have made a mistake-is it in the way I have created the hierarchy or is it in the way I am trying to access and write to a certain location within array 1 inside array2?
I would greatly appreciate your thoughts.
TIA
Vinod

Answers (0)

Community Treasure Hunt

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

Start Hunting!