How to solve :'Error using prod. Invalid data type. First argument must be numeric or logical.'
Show older comments
Hi,
In this part of the code:
--------------------------------------
if (prod(children(Term(ll)))~=Term(ll))
AAA=size(children(Term(ll)));
Chi(ll,1:AAA(1,2))=children(Term(ll));
Chi(ll,:)=expand(Chi(ll));
else
AAA=[1 1];
Chi(ll,1:1)=Term(ll);
end
---------------------------------------
I get the following error:
---------------------------------------
Error using prod
Invalid data type. First argument must be numeric or logical.
Error in Generalized_Integration_Code (line 130)
if (prod(children(Term(ll)))~=Term(ll))
----------------------------------------
Can you please help me how can I solve the error?
Thanks
Accepted Answer
More Answers (1)
Matt J
on 7 Mar 2022
We've no way of running your code, but I'm pretty certain if you just examine,
K>> class(children(Term(ll)))
all will be clear.
10 Comments
zahra rashidi
on 7 Mar 2022
Torsten
on 7 Mar 2022
If
KK = class(children(term(ll)))
does not give numeric or logical as result, you cannot apply prod.
So output KK.
zahra rashidi
on 7 Mar 2022
Matt J
on 7 Mar 2022
Did you mean perhaps to have,
prod( children{Term(ll)} )
zahra rashidi
on 7 Mar 2022
If there's a difference in the two codes, it was in the creation of 'children', not any part of the code you've posted. The error message is certainly not Matlab-version related. prod() will not work on cells and never has.
children=[1,2,3];
prod(children),
children={1,2,3};
prod(children)
zahra rashidi
on 7 Mar 2022
Matt J
on 7 Mar 2022
Likely because of Walter's answer. Regardless, full clarity can only come if you attach children in a .mat file.
zahra rashidi
on 8 Mar 2022
Walter Roberson
on 8 Mar 2022
Mathworks changed the output of children() to make the output for scalar input more consistent with the output for non-scalar input. Both cases now return cell array.
Categories
Find more on Function Creation 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!