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!