- Upload the complete code (upload the code using the paperclip button if the code is large).
- Give the complete error message, which is all of the red text. There is lots of useful information in this message that we can use to help you.
for about three days I have had this error message: Cell contents reference from a non-cell array object.
1 view (last 30 days)
Show older comments
lambda_snr_vec = ones(1,nodes);
sigma_sample = 2;
Counter = 1;
for i=1:steps
for child=1:nodes
% sampling sigma
lambda_snr = lambda_snr_vec(1,child);
sum_Delta2 = 0;
for component=1:Kg; * * _ |%%%%%the problem is here%%%%%%%| _ * *
sum_Delta2 = sum_Delta2 +y{child}{component}'*inv(eye(length(find(vector==component)))+lambda_snr* X{child}{component}'* X{child}{component})*y{child}{component};
end
A=alpha_sig+((m-1)/2);
B=beta_sig+(sum_Delta2/2);
new_sigma_sample= gamrnd(A,B);
%sampling Wg,k
for component=1:Kg
sigma_star = inv(lambda_snr * eye(cardinality_parents{child}+1) + X{child}{component}*X{child}{component}');
A = sigma_star * X{child}{component} * y{child}{component};
B = new_sigma_sample*sigma_star;
regress_par_sample{component} = mvnrnd(A,B)';
end
%sampling lambda
sum_regress_para = 0;
for component=1:Kg;
sum_regress_para = sum_regress_para + regress_par_sample{component}'*regress_par_sample{component};
end
A = alpha_sig+(Kg*(cardinality_parents{child}+1)/2);
B = beta_sig+(1/2 * new_sigma_sample* sum_regress_para);
new_lambda_sample= gamrnd(A,B);
3 Comments
Guillaume
on 15 Jun 2015
The error message should have given you a line where the error occurs. Which line is that? As a rule, when asking help about an error message, paste the entire error message (everything in red) in the body of the question.
Accepted Answer
Guillaume
on 15 Jun 2015
There are a number of cell references used in your code. Are all of them actually cell arrays? In particular:
- Are X and y both cell arrays. If not, X{child} or y{child} is invalid
- If they are, are all the cell themselves cell arrays. If not, X{child}{componenent} or y{child}{component} is not valid.
- Has regress_par_sample been declared as a cell array
dbstop if error
Run your code, and when it stops see what the content and type of X{child} or y{child} is. Most likely it's empty or not a cell array:
x{child} %view content
y{child} %view content
class(x{child}) %view type, must be cell
class(y{child}) %view type, must be cell
0 Comments
More Answers (4)
David H
on 15 Jun 2015
The problem is likely that one of X or y is not defined as a cell array.
Can you put two lines of code before the error which output class(X) and class (y)? If one comes out as something that isn't "cell" look through the rest of the code to find where you might have accidentally overwritten it.
0 Comments
Walter Roberson
on 15 Jun 2015
At the command prompt, give the command
dbstop if error
and then run the program. When it stops,
if ~iscell(X)
fprintf(2,'X is not a cell!');
else
for KKK = 1 : length(X)
if ~iscell(X{KKK})
fprintf(2,'X{%d} is not a cell!', KKK);
break;
end
end
end
if ~iscell(y)
fprintf(2,'y is not a cell!');
else
for KKK = 1 : length(y)
if ~iscell(y{KKK})
fprintf(2,'y{%d} is not a cell!', KKK);
break;
end
end
end
1 Comment
Walter Roberson
on 15 Jun 2015
Your statement
y=y{child}{component}'
is overwriting all of y with the current component. You do not make the same mistake for x as you use
X=x{child}{component};
notice that the output variable "X" is not the same as the input variable "x" so the treatment of x is fine in that line. On the other hand your line 59 is going to try to access X{child}{component} and that doesn't exist.
You need to review your code and pay attention to the variable names.
See Also
Categories
Find more on Logical 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!