How to solve :'Error using prod. Invalid data type. First argument must be numeric or logical.'
Afficher commentaires plus anciens
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
Réponse acceptée
Plus de réponses (1)
Matt J
le 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 commentaires
zahra rashidi
le 7 Mar 2022
Torsten
le 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
le 7 Mar 2022
Matt J
le 7 Mar 2022
Did you mean perhaps to have,
prod( children{Term(ll)} )
zahra rashidi
le 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
le 7 Mar 2022
Matt J
le 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
le 8 Mar 2022
Walter Roberson
le 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.
Catégories
En savoir plus sur Function Creation dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!