From: Steven Lord on

"TideMan" <mulgor(a)gmail.com> wrote in message
news:3b43c4f4-75ac-48dc-8dbe-94876e8f8482(a)h16g2000prf.googlegroups.com...
On Apr 27, 10:55 am, "Stephen " <hphil...(a)utk.edu> wrote:
> "Steven Lord" <sl...(a)mathworks.com> wrote in message
> <hr45t1$96...(a)fred.mathworks.com>...

*snip*

> I suspect you have done what Steven surmised and you have further if
> statements below this snippet of code.
> You need to put them all within one if statement, separated by elseifs
> So it would look like this:
> if 0<=Hn<=90
> do stuff
> elseif 90 <= Hn < 180

*snip*

And, of course, this code will never, ever reach beyond that first IF.

"if 0 <= Hn <= 90" is equivalent to "if ((0 <= Hn) <= 90)". Since (0 <= Hn)
can only return either 0's and/or 1's and both those values are less than or
equal to 90, this IF statement's condition is ALWAYS satisfied. Therefore
your ELSEIFs and ELSE blocks are dead code.

If Hn is a scalar, rewrite this as "if (0 <= Hn) && (Hn <= 90)". If Hn is
not a scalar, you probably want to use logical indexing:

case1 = (0<= Hn) & (Hn <= 90);
case2 = (90< Hn) & (Hn <= 180);
case3 = (180< Hn) & (Hn <= 270);
case4 = (270< Hn) & (Hn <= 360);
case5 = ~(case1 | case2 | case3 | case4);

Now perform whatever you want to do to Hn values in the 1st quadrant by
indexing into Hn using the case1 logical array.

% Preallocate result to be the same size as Hn
result = zeros(size(Hn));

% Process case 1 and fill in the appropriate elements of result
result(case1) = processFirstCase(Hn(case1));

% similarly for cases 2, 3, 4, and 5.

or you could iterate through the elements of Hn and process each one in turn
using the (0<= Hn) && (Hn <= 90) code.

--
Steve Lord
slord(a)mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ