How to solve :'Error using prod. Invalid data type. First argument must be numeric or logical.'

5 vues (au cours des 30 derniers jours)
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

Walter Roberson
Walter Roberson le 7 Mar 2022
Modifié(e) : Walter Roberson le 7 Mar 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 commentaires
Walter Roberson
Walter Roberson le 8 Mar 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'.

Connectez-vous pour commenter.

Plus de réponses (1)

Matt J
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
Walter Roberson
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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Function Creation dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by