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

11 次查看(过去 30 天)
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

采纳的回答

Walter Roberson
Walter Roberson 2022-3-7
编辑:Walter Roberson 2022-3-7
"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 个评论
Walter Roberson
Walter Roberson 2022-3-8
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'.

请先登录,再进行评论。

更多回答(1 个)

Matt J
Matt J 2022-3-7
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 个评论
Walter Roberson
Walter Roberson 2022-3-8
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Function Creation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by