Zero pad using piecewise.
22 次查看(过去 30 天)
显示 更早的评论
Hello,
I need help zero padding a function.
This the code for the function:
Vr = (eps*((r0./r).^12));
Va = (-eps*(2*(r0./r).^6));
V = Vr+Va
I need to zero pad it so that all values of V that are above 0 are set to 0.
So in written forms I need this:
{0, V>0}
V=
{V, V<0}
I tried this so far:
V = piecewise(Vr+Va>0,0, Vr+Va<0,Vr+Va);
but I keep getting this error:
Incorrect number or types of inputs or outputs for function piecewise.
Error in Project_2 (line 22)
V = piecewise(Vr+Va>0,0, Vr+Va<0,Vr+Va);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
0 个评论
采纳的回答
Voss
2024-10-31,20:04
"I need ... that all values of V that are above 0 are set to 0."
V(V > 0) = 0;
or
V = min(V,0);
0 个评论
更多回答(1 个)
Walter Roberson
2024-10-31,19:46
piecewise() requires that the first input be a symbolic expression.
Your Vr+Va is likely numeric.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Create Links to External Requirements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!