Fixing a plot with error message: "Function behaves unexpectedly on array inputs...properly vectorize your function"
显示 更早的评论
I am trying to plot my function "massactcup_frustrumwt" for a range of different values of "t" but every time I try to plot it, though it plots properly, I get an error message: "Function behaves unexpectedly on array inputs. To improve performance, properly vectorize your function to return an output with the same size and shape as the input arguments. "
Can someone please explain to me what this error message means? What does it mean to properly vectorize a function? Also, how should I change my function so that it plots without producing this error message? I want to be able to fix this problem in the future. My function is below:
function [y] = massactcup_frustrumwt (h, rob, rot, t)
rib=rob-t;
rit=rot-t;
A=(rob^2+2*rob*rot+3*rot^2)-(rib^2+2*rib*rit+3*rit^2);
B=(rob^2+rob*rot+rot^2)-(rib^2+rib*rit+rit^2);
COGz=h*A/(4*B);
y=COGz;
end
% Units: everything is in cm. y and y0 are expressed in cm
Thank you,
Jordan
1 个评论
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!