Stop matlabFunction converting operators to element-wise operators
1 次查看(过去 30 天)
显示 更早的评论
How do I stop matlabFunction converting operators to element-wise operators when forming a function handle from a symbolic expression? For example with mtimes and times, or mpower and power.
syms x y;
fh = matlabFunction(mpower(x, y))
This is particularly annoying when wanting to use the function handle on classes which have the operator defined, but not the element-wise operator. For example, a transfer function:
% this works
tf('s')^3
% this does not
fh(tf('s'), 3)
This also has become a problem using the 'realp' and 'genmat' classes. I have had to define the element-wise operators in the classes myself, but surely this cannot be the optimal solution.
0 个评论
回答(1 个)
Matt J
2021-10-5
Perhaps as follows?
syms x y;
str = func2str( matlabFunction(mpower(x, y)) );
str(str=='.')='';
fh=str2func(str)
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!