Path: news.mathworks.com!not-for-mail
From: "Ongun Palaoglu" <ongun@mac.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: if statements
Date: Fri, 10 Oct 2008 18:54:02 +0000 (UTC)
Organization: Florida institute of Technolgy
Lines: 77
Message-ID: <gco8ca$qi0$1@fred.mathworks.com>
References: <gcmi9m$lbj$1@fred.mathworks.com> <gcn6f7$p95$1@fred.mathworks.com> <gcnmai$4d$1@fred.mathworks.com>
Reply-To: "Ongun Palaoglu" <ongun@mac.com>
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 1223664842 27200 172.30.248.37 (10 Oct 2008 18:54:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 10 Oct 2008 18:54:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1541435
Xref: news.mathworks.com comp.soft-sys.matlab:494611


"Steven Lord" <slord@mathworks.com> wrote in message <gcnmai$4d$1@fred.mathworks.com>...
> 
> "Jos " <DELjos@jasenDEL.nl> wrote in message 
> news:gcn6f7$p95$1@fred.mathworks.com...
> > "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
> 
> In addition to Jos's comments, this line may not do what you think it will 
> do.  From HELP IF:
> 
>     The statements are executed if the real part of the expression
>     has all non-zero elements.
> 
> So unless ALL of the elements of id are equal to 0, the IF condition will 
> never be satisfied.  If you want to satisfy the IF condition if ANY of the 
> elements of id are equal to 0, you'd want:
> 
> if any(id == 0)
> 
> or, to account for floating-point as Jos said,
> 
> if any(abs(id) < 1e-5)
> 
> -- 
> Steve Lord
> slord@mathworks.com 
> 
hey, 

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

this part works perfecly fine, when and he result is 3 by 2 matrix, and at the first row's first number is positive  and last 2 is 0. 
so i want to compare the values,i want to pull zeros out of the ans, and want to call them saturation, and i want to use them for another function to calculate another thing. and it is same for the first number.

thats why I said 
if id=0
disp('curoff')
else
disp('sat')
end
after this point i want to call the saturated values, for another function