How to solve :'Error using prod. Invalid data type. First argument must be numeric or logical.'
Mostrar comentarios más antiguos
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
Respuesta aceptada
Más respuestas (1)
Matt J
el 7 de Mzo. de 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 comentarios
zahra rashidi
el 7 de Mzo. de 2022
Torsten
el 7 de Mzo. de 2022
If
KK = class(children(term(ll)))
does not give numeric or logical as result, you cannot apply prod.
So output KK.
zahra rashidi
el 7 de Mzo. de 2022
Matt J
el 7 de Mzo. de 2022
Did you mean perhaps to have,
prod( children{Term(ll)} )
zahra rashidi
el 7 de Mzo. de 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
el 7 de Mzo. de 2022
Matt J
el 7 de Mzo. de 2022
Likely because of Walter's answer. Regardless, full clarity can only come if you attach children in a .mat file.
zahra rashidi
el 8 de Mzo. de 2022
Walter Roberson
el 8 de Mzo. de 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.
Categorías
Más información sobre Function Creation en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!