How to solve :'Error using prod. Invalid data type. First argument must be numeric or logical.'
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
zahra rashidi
el 7 de Mzo. de 2022
Comentada: Walter Roberson
el 8 de Mzo. de 2022
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
0 comentarios
Respuesta aceptada
Walter Roberson
el 7 de Mzo. de 2022
Editada: Walter Roberson
el 7 de Mzo. de 2022
"Starting in R2020b, the syntax subexpr = children(expr) for a scalar input expr returns subexpr as a nonnested cell array instead of a vector"
So you will need to replace
prod(children(Term(ll)))
with
prod([struct('T',children(Term(ll))).T{:}])
Or previously construct
symcell2mat = @(v) [v{:}]
with
prod(symcell2mat(children(Term(ll))))
8 comentarios
Walter Roberson
el 8 de Mzo. de 2022
The case where the product of the children is not equal to the original is simply the case where the original item is not a product. Which is something that could be tested using isSymType testing for numbers or variables or 'times'.
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
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.
Ver también
Categorías
Más información sobre Function Creation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!