## error; Unable to perform assignment because the left and right sides have a different number of elements.

### huy thành (view profile)

on 13 Oct 2019
Latest activity Answered by Walter Roberson

### Walter Roberson (view profile)

on 13 Oct 2019
function OKButtonPushed(app, event)
Cox=app.CoxEditField.Value;
Vt=app.VtEditField.Value;
lamda=app.lamdaEditField.Value;
W=app.WEditField.Value;
L=app.LEditField.Value;
Vgs=[0.5 2 3.5 4.5];
Vds=0:0.1:5;
Ids=[0 0 0 0];
for i=1:4
if Vgs(i)<=Vt
Ids(i)=0;
elseif Vgs(i)>Vt||Vds<(Vgs(i)-Vt)
Ids(i)=Cox.*(W/L).*((Vgs(i)-Vt).*Vds-Vds.*Vds/2).*(1+lamda.*Vds);
elseif Vgs(i)>Vt||Vds>(Vgs(i)-Vt)
Ids(i)=Cox.*(W/L).*(Vgs(i)-Vt).*(Vgs(i)-Vt).*(1+lamda.*Vds);
end
end
plot(app.UIAxes,Vds,Ids);

Image Analyst

### Image Analyst (view profile)

on 13 Oct 2019 ### Walter Roberson (view profile)

on 13 Oct 2019

Vds=0:0.1:5;
Vds is a vector of length 51
elseif Vgs(i)>Vt||Vds<(Vgs(i)-Vt)
Notice on the right hand side of the || that Vds is a vector and you are comparing that vector to a scalar. The result would be a vector. The right hand side of the || would be a vector. However, the sides of || must be scalars. You would get away with it in the case that the left side is true. When is the left side true? Well notice the previous test:
if Vgs(i)<=Vt
Under what circumstances could Vgs(i)<=Vt be false in order to fall into the elseif and yet Vgs(i)>Vt also be false to invoke the right hand side of the || ? The answer is that for any numeric values, Vgs(i)<=Vt and Vgs(i)>Vt cannot be simultaneously be false: the only way you could get to the right side of the || is if one of Vgs(i) or Vt were NaN . So unless you are dealing with NaN, one of the two Vgs(i)<=Vt or Vts(i)>Vt will be true, so the right hand side of the || is not needed and the second elseif are not needed.
Ids(i)=Cox.*(W/L).*((Vgs(i)-Vt).*Vds-Vds.*Vds/2).*(1+lamda.*Vds);
Vds is a vector, so your four references to Vds in the expression on the right hand side all force the right hand side to be a vector expression. You cannot store the result of a vector expression into a single scalar.