필터 지우기
필터 지우기

I need help with using the If-Else loop containing scalar and nonscalar

조회 수: 5 (최근 30일)
Steven
Steven 2013년 1월 21일
Create a plot of iD as a function of vDS from 0 ≤ vDS ≤ 8 V, for three values of vGS =2, 3, and 4 V.
Constants: Kn=0.2 mA/V2; VTN =1.2 V; λ=0.01 V-1.
Here is my work I have so far:
Vds = 0:0.1:8;
Vgs = 2:1:4;
kn = 0.2;
Vtn = 1.2;
lambda = 0.01;
Vds_Sat = Vgs - Vtn;
if (Vds <= Vds_Sat)
ID = Kn*(2*(Vgs-Vtn)*Vds - (Vds^2));
else (Vds >= Vds_Sat)
ID = Kn*((Vgs - Vtn)^2*(1 + lambda * Vds));
end
plot(Vds.,ID)
It is telling me I have an error on line 7 and that my matrix dimension must agree, could you please help me with this?
  댓글 수: 1
Walter Roberson
Walter Roberson 2013년 1월 22일
There is no such thing as an "If loop". There is an "if statement". Loops execute the body multiple times; statements execute the body (or not) exactly one time.

댓글을 달려면 로그인하십시오.

답변 (1개)

Matt J
Matt J 2013년 1월 21일
This operation
Vds <= Vds_Sat
does not make sense since the left and right hand side are vectors of different sizes.
  댓글 수: 9
Steven
Steven 2013년 1월 21일
I got the plot to work but it only plots the case when Vgs = 4. How can I obtain the plots when Vgs = 2 & 3?
Matt J
Matt J 2013년 1월 21일
편집: Matt J 2013년 1월 21일
Use the HOLD command. Or, plot to different figure windows
figure; plot(....)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Labels and Annotations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by