How to solve :'Error using prod. Invalid data type. First argument must be numeric or logical.'
4 views (last 30 days)
Show older comments
zahra rashidi
on 7 Mar 2022
Commented: Walter Roberson
on 8 Mar 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 Comments
Accepted Answer
Walter Roberson
on 7 Mar 2022
Edited: Walter Roberson
on 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 Comments
Walter Roberson
on 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'.
More Answers (1)
Matt J
on 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 Comments
Walter Roberson
on 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.
See Also
Categories
Find more on Function Creation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!