Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: if statements
Date: Fri, 10 Oct 2008 09:15:19 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 49
Message-ID: <gcn6f7$p95$1@fred.mathworks.com>
References: <gcmi9m$lbj$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1223630119 25893 172.30.248.37 (10 Oct 2008 09:15:19 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 10 Oct 2008 09:15:19 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 870065
Xref: news.mathworks.com comp.soft-sys.matlab:494529


"Ongun Palaoglu" <ongun@mac.com> wrote in message <gcmi9m$lbj$1@fred.mathworks.com>...
> hello guys i am trying to use the if command,
>  my code:
> 
> %setting parameter
> vtn = 0.75;
> vds = [0.2 2.5 0];
> vgs = [2 2 0];
> knp=[200*10^-6 300*10^-6];
> kp=knp*10;
> i = 1; len = length (vgs);

Since this loop executes a fixed number of times, you should change it into a for-loop
for i=1:len,
   x(i) =
end

which you can vectorize using the dot notation (.*)
x = vds .* (vgs - vtn - vds/2);

> while i <= len
>     x(i)=vds(i)*(vgs(i)-vtn-vds(i)/2);
>     i = i + 1;
> end

I am pretty sure this "while" does not belong here:

> while

In general, it is a bad idea to compare floating point numbers exactly. Try abs(id)< 0.00001

> id=kp.'*x
> if id == 0
>     disp('cutoff')
> else 
>     disp('saturation')
> end
> 
> this is just an exercise i created. what is teh mistake in here. i want to display the cutoff value and saturation value. for example; 2 saturation.

To show the number, use for instance
disp(id)
> 
> and I also want to improve this code, i want to use saturation values on a different function.
> 
> thanks a ot.

hth
Jos