필터 지우기
필터 지우기

How do i get it to show Error when it is a negative number

조회 수: 4 (최근 30일)
Tony Hill
Tony Hill 2014년 5월 7일
답변: Image Analyst 2014년 5월 8일
function V_out = Final_part4(V_in, R1, R2)
V_out = (R2/(R1+R2))*V_in;
if R1 <=0 && R2<= 0
error ('No negative numbers allowed');
end
end
My question is how do i have the output show error when R1 and R2 are less than zero,

답변 (2개)

Star Strider
Star Strider 2014년 5월 8일
편집: Star Strider 2014년 5월 8일
The code you have will throw an error and abort the function if the conditions are met. It should not return anything in V_out.
Actually, although neither R1 nor R2 can be negative, R2 can be zero providing R1 is greater than zero. In that case, the little voltage divider network shorts the output to ground, and V_out = 0.

Image Analyst
Image Analyst 2014년 5월 8일
I believe you want
if R1 <= 0 || R2 <= 0 % or <
instead of
if R1 <= 0 && R2 <= 0
This will throw an error if either is less than 0

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by