How to solve :'Error using prod. Invalid data type. First argument must be numeric or logical.'
Ältere Kommentare anzeigen
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
Akzeptierte Antwort
Weitere Antworten (1)
Matt J
am 7 Mär. 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 Kommentare
zahra rashidi
am 7 Mär. 2022
Torsten
am 7 Mär. 2022
If
KK = class(children(term(ll)))
does not give numeric or logical as result, you cannot apply prod.
So output KK.
zahra rashidi
am 7 Mär. 2022
Matt J
am 7 Mär. 2022
Did you mean perhaps to have,
prod( children{Term(ll)} )
zahra rashidi
am 7 Mär. 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
am 7 Mär. 2022
Matt J
am 7 Mär. 2022
Likely because of Walter's answer. Regardless, full clarity can only come if you attach children in a .mat file.
zahra rashidi
am 8 Mär. 2022
Walter Roberson
am 8 Mär. 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.
Kategorien
Mehr zu Function Creation finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!