Cell contents assignment to a non-cell array object?

Hi there,
I have written this piece of code to store all the combination into a array of matrices.
for i=1:4,
m = combnk(1:4,i)
tester{i} = repmat(m,1)
end
When I tested it separately, it works fine. But when I combined it with other code in my project, the matlab gave me warning regarding tester{i} = repmat(m,1): Cell contents assignment to a non-cell array object
Anybody can enlighten me on this issue? Thanks a million in advance!

2 Comments

Is tester pre-declared or is it just created and resized in the loop?
I have tested the other part of the code. No error. Just in case, I attached the full code here (but no excel sheet):
% Load demand excelfile
[num_demand,txt_demand,raw_demand] = xlsread('Testing_Demand.xlsx');
A = num_demand;
APrime = sum(A);
NumberOfElementsInBigMatrix = APrime(1,3);
tester = (round(NumberOfElementsInBigMatrix/2));
BigMatrix = cell(tester^2,(NumberOfElementsInBigMatrix-tester)^2);
% load supply excelfile
[num_incoming,txt_incoming,raw_incoming] = xlsread('Testing_Incoming.xlsx');
B = num_incoming;
[num_pivot,txt_pivot,raw_pivot] = xlsread('CoreToPartsPivot.xlsx');
C = num_pivot;
%convert demand core to part level
D = zeros(940,1); %matrix to store converted components
for j=1:940,
for i=1:27,
%dont have 10R6700/reserve the last one as 10R6700; But components are not calculated
if isnan(C(j,i))
else
D(j,1)= D(j,1) + B(i,3)*C(j,i);
end
end
end
for i=1:4,
m = combnk(1:4,i)
tester{i} = repmat(m,1)
end
for i=1:4,
tester{i}
end

Sign in to comment.

 Accepted Answer

Adam
Adam on 7 Mar 2015
Edited: Adam on 7 Mar 2015
tester = (round(NumberOfElementsInBigMatrix/2));
will create tester as a double array. Then later on you try to assign to it as though it is a cell array in the for loop you provided at the top. If you created it as a double you cannot then assign to it with cell array syntax.
The initial code works standalone because tester was not previously declared as a double so it is created in the loop as a cell array.

More Answers (0)

Categories

Find more on MATLAB 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!