Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
A complex mesh grid boundary for plotting

Subject: A complex mesh grid boundary for plotting

From: Bookie via MathKB.com

Date: 6 May, 2008 22:30:22

Message: 1 of 14

Hello,

  Does anyone know what the problem might be in a code I've written to
describe an irregular-shaped mesh grid boundary. I have a region of points
to plot against a function z. The "shadow" cast by this region on the x-y
plane of my surface plot, is a region bound above by the bottom right
quadrant of a circle, and below by the top right quadrant of a circle, and on
the left by a vertical line and on the right by a line-y=mx+b. I've compiled
my program but it is generating a 4 sided shape that doesn't have any curves
at the top or bottom. I've plotted my circles and lines separately to make
sure that my equations are accurate. If anyone has any ideas on what's wrong
with my code that would be a great help!

Matlab code:

clear all
clc
% Mesh points
m = 21;
n = 21;
T = zeros(5,n,m);
[ix,iy] = meshgrid(1:m,1:n);
minX = a;
maxX = b;
midX = c;
% y-values change over the range of x
%Equation of first lower boundary ranging from x = a to c:
% y = sqrt(r1^2-(x-X1)^2)-Y1 (top right quadrant)
%Equation of 2nd lower boundary ranging from x = c to b:
% y = m*x+b
%Equation of upper boundary ranging from x = a to b:
% y = (-1*sqrt(r2^2-(x-X2)^2)+Y2 (bottom right quadrant)
% X1,Y1 and X2,Y2 are centre coordinates of circles (constants)
% r1,r2 are circle radii (constants)
x = a + (ix-1)*(b-a)/(m-1); % a <= x <= b
if a <= x < c;
    y = (sqrt(r1^2-(x-X1).^2)-Y1) + (iy-1).*((-1*sqrt(r2^2-(x-X2).^2)+Y2)-
(sqrt(r1^2-(x-X1).^2)-Y1))/(n-1); % circle1 <= y <= circle2
    else c <= x <= b;
        y = (m.*x+b) + (iy-1).*((-1*sqrt(r2^2-(x-X2).^2)+Y2)-(m.*x+b))/(n-1);
% m*x+b <= y <= circle2
end
for i = 1:n
    for j = 1:m
        [T(:,i,j)] = Function(x(i,j),y(i,j));
    end
end
figure
Z = squeeze(T(1,:,:));
surf(x,y,real(Z))
axis tight %want x & y axes tight so curves in x-y plane are not skewed
colormap hsv
colorbar

Thanks for your help!

Bookie

--
Message posted via MathKB.com
http://www.mathkb.com/Uwe/Forums.aspx/matlab/200805/1

Subject: A complex mesh grid boundary for plotting

From: Bookie via MathKB.com

Date: 6 May, 2008 22:34:02

Message: 2 of 14

Hi,

I also get an orange underline at the 3rd line of my if loop:

else c <= x <= b;

that "<= produces a value that appears to be unused."

Thanks

Bookie

Bookie wrote:
>Hello,
>
> Does anyone know what the problem might be in a code I've written to
>describe an irregular-shaped mesh grid boundary. I have a region of points
>to plot against a function z. The "shadow" cast by this region on the x-y
>plane of my surface plot, is a region bound above by the bottom right
>quadrant of a circle, and below by the top right quadrant of a circle, and on
>the left by a vertical line and on the right by a line-y=mx+b. I've compiled
>my program but it is generating a 4 sided shape that doesn't have any curves
>at the top or bottom. I've plotted my circles and lines separately to make
>sure that my equations are accurate. If anyone has any ideas on what's wrong
>with my code that would be a great help!
>
>Matlab code:
>
>clear all
>clc
>% Mesh points
>m = 21;
>n = 21;
>T = zeros(5,n,m);
>[ix,iy] = meshgrid(1:m,1:n);
>minX = a;
>maxX = b;
>midX = c;
>% y-values change over the range of x
>%Equation of first lower boundary ranging from x = a to c:
>% y = sqrt(r1^2-(x-X1)^2)-Y1 (top right quadrant)
>%Equation of 2nd lower boundary ranging from x = c to b:
>% y = m*x+b
>%Equation of upper boundary ranging from x = a to b:
>% y = (-1*sqrt(r2^2-(x-X2)^2)+Y2 (bottom right quadrant)
>% X1,Y1 and X2,Y2 are centre coordinates of circles (constants)
>% r1,r2 are circle radii (constants)
>x = a + (ix-1)*(b-a)/(m-1); % a <= x <= b
>if a <= x < c;
> y = (sqrt(r1^2-(x-X1).^2)-Y1) + (iy-1).*((-1*sqrt(r2^2-(x-X2).^2)+Y2)-
>(sqrt(r1^2-(x-X1).^2)-Y1))/(n-1); % circle1 <= y <= circle2
> else c <= x <= b;
> y = (m.*x+b) + (iy-1).*((-1*sqrt(r2^2-(x-X2).^2)+Y2)-(m.*x+b))/(n-1);
>% m*x+b <= y <= circle2
>end
>for i = 1:n
> for j = 1:m
> [T(:,i,j)] = Function(x(i,j),y(i,j));
> end
>end
>figure
>Z = squeeze(T(1,:,:));
>surf(x,y,real(Z))
>axis tight %want x & y axes tight so curves in x-y plane are not skewed
>colormap hsv
>colorbar
>
>Thanks for your help!
>
>Bookie

--
Message posted via http://www.mathkb.com

Subject: A complex mesh grid boundary for plotting

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 6 May, 2008 22:51:35

Message: 3 of 14

In article <83c42f77f35ee@uwe>, Bookie via MathKB.com <u43093@uwe> wrote:

>if a <= x < c;

if (a <= x) & (x < c)

> y = (sqrt(r1^2-(x-X1).^2)-Y1) + (iy-1).*((-1*sqrt(r2^2-(x-X2).^2)+Y2)-
>(sqrt(r1^2-(x-X1).^2)-Y1))/(n-1); % circle1 <= y <= circle2
> else c <= x <= b;

Did you mean,

elseif (c <= x & x <= b)

Or is c <= x <= b; just a comment, or are you attempting to
execute ((c <= x) <= b) and then throw away the result ??

> y = (m.*x+b) + (iy-1).*((-1*sqrt(r2^2-(x-X2).^2)+Y2)-(m.*x+b))/(n-1);
>% m*x+b <= y <= circle2
>end
--
amazon.com's top 8 books about "walter" are Kotzwinkle/ Gundy/ Colman's
"Walter the Farting Dog"

Subject: A complex mesh grid boundary for plotting

From: Bookie via MathKB.com

Date: 6 May, 2008 23:30:54

Message: 4 of 14

Hi,

Yes, I want to say when x is equal to and greater than 'a' but less than 'c'
then y is calculated in a certain way. So yes, if (a <= x) & (x < c);
describes what I mean as well. I guess this is different from if a <= x < c;?


Then I say when x is equal to and greater than 'c' but less than and equal to
'b' then y is calculated accordingly. "elseif (c <= x & x <= b)" is what I
mean then. I don't want this is as a comment but actual code to help me
generate the remaining of the results for y over the range of x values
between c and b.

As x values range from 'a' to 'b,' with 'c' being some midpoint, I want my y
values to be calculated accordingly. So I want to generate and keep my
corresponding y values that are generated over the range of x values between
'a' and 'b. I have a comment at the end of each of my y equations only
describing that y is calculated between functions i.e. "% circle1 <= y <=
circle2"

I hope that answers what you've asked.

Thanks Walter!

Bookie

Walter Roberson wrote:
>>if a <= x < c;
>
>if (a <= x) & (x < c)
>
>> y = (sqrt(r1^2-(x-X1).^2)-Y1) + (iy-1).*((-1*sqrt(r2^2-(x-X2).^2)+Y2)-
>>(sqrt(r1^2-(x-X1).^2)-Y1))/(n-1); % circle1 <= y <= circle2
>> else c <= x <= b;
>
>Did you mean,
>
>elseif (c <= x & x <= b)
>
>Or is c <= x <= b; just a comment, or are you attempting to
>execute ((c <= x) <= b) and then throw away the result ??
>
>> y = (m.*x+b) + (iy-1).*((-1*sqrt(r2^2-(x-X2).^2)+Y2)-(m.*x+b))/(n-1);
>>% m*x+b <= y <= circle2
>>end

--
Message posted via http://www.mathkb.com

Subject: A complex mesh grid boundary for plotting

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 6 May, 2008 23:54:54

Message: 5 of 14

In article <fvqndn$t73$1@canopus.cc.umanitoba.ca>,
Walter Roberson <roberson@ibd.nrc-cnrc.gc.ca> wrote:
>In article <83c42f77f35ee@uwe>, Bookie via MathKB.com <u43093@uwe> wrote:
>
>>if a <= x < c;

>if (a <= x) & (x < c)

Ah, I just realized that I wrote that assuming that x was a vector, but
that if x -is- a vector, then you are going to hit a behaviour
that you should know about.

If a, c, and x are all single numbers, none of them vectors, then

if a <= x && x < c

is more efficient than using & instead of && .

If x is a vector (more than one element), then the expression
(a <= x & x < c) will produce a vector of logical results. The
question then would what you would want to do if some of the results
were true and some were false. The default in an 'if' statement is
to only process the 'if' statement if *all* of the values are true.
--
  "Every intellectual product must be judged from the point of view
  of the age and the people in which it was produced."
                                              -- Walter Horatio Pater

Subject: A complex mesh grid boundary for plotting

From: Roger Stafford

Date: 7 May, 2008 00:13:04

Message: 6 of 14

"Bookie via MathKB.com" <u43093@uwe> wrote in message
<83c42f77f35ee@uwe>...
> Hello,
>
> Does anyone know what the problem might be in a code I've written to
> describe an irregular-shaped mesh grid boundary. I have a region of
points
> to plot against a function z. The "shadow" cast by this region on the x-y
> plane of my surface plot, is a region bound above by the bottom right
> quadrant of a circle, and below by the top right quadrant of a circle, and on
> the left by a vertical line and on the right by a line-y=mx+b. I've compiled
> my program but it is generating a 4 sided shape that doesn't have any
curves
> at the top or bottom. I've plotted my circles and lines separately to make
> sure that my equations are accurate. If anyone has any ideas on what's
wrong
> with my code that would be a great help!
>
> Matlab code:
>
> clear all
> clc
> % Mesh points
> m = 21;
> n = 21;
> T = zeros(5,n,m);
> [ix,iy] = meshgrid(1:m,1:n);
> minX = a;
> maxX = b;
> midX = c;
> % y-values change over the range of x
> %Equation of first lower boundary ranging from x = a to c:
> % y = sqrt(r1^2-(x-X1)^2)-Y1 (top right quadrant)
> %Equation of 2nd lower boundary ranging from x = c to b:
> % y = m*x+b
> %Equation of upper boundary ranging from x = a to b:
> % y = (-1*sqrt(r2^2-(x-X2)^2)+Y2 (bottom right quadrant)
> % X1,Y1 and X2,Y2 are centre coordinates of circles (constants)
> % r1,r2 are circle radii (constants)
> x = a + (ix-1)*(b-a)/(m-1); % a <= x <= b
> if a <= x < c;
> y = (sqrt(r1^2-(x-X1).^2)-Y1) + (iy-1).*((-1*sqrt(r2^2-(x-X2).^2)+Y2)-
> (sqrt(r1^2-(x-X1).^2)-Y1))/(n-1); % circle1 <= y <= circle2
> else c <= x <= b;
> y = (m.*x+b) + (iy-1).*((-1*sqrt(r2^2-(x-X2).^2)+Y2)-(m.*x+b))/
(n-1);
> % m*x+b <= y <= circle2
> end
> for i = 1:n
> for j = 1:m
> [T(:,i,j)] = Function(x(i,j),y(i,j));
> end
> end
> figure
> Z = squeeze(T(1,:,:));
> surf(x,y,real(Z))
> axis tight %want x & y axes tight so curves in x-y plane are not skewed
> colormap hsv
> colorbar
>
> Thanks for your help!
>
> Bookie
---------
  In addition to Walter's two criticism's I have one more, and it is a serious
one. You have used the 'if' function improperly here. When you put an array
of logical values after the 'if', rather than a single scalar quantity, as you have
done above, it interprets them as if you had placed 'all' around them. What
else could it do? It is limited to going the one way or the other and not some
quantum-computer combination of both.

  In other words, if you have:

 x = [1 2 3 4 5];
 if x <= 3
  y = x;
 else
  y = -x;
 end

then you will get y = [-1 -2 -3 -4 -5], not the [1 2 3 -4 -5]] you are
apparently expecting, because the expression x<=3 is not true in all cases.
The execution of the 'if' here is to either execute y = x; or else y = -x; in their
respective entireties, and not some of one and some of the other.

  To make this go the way I think you want, it would have to be written in this
fashion:

 x = [1 2 3 4 5];
 y = (x<=3).*x + (x>3)*7;

This is the equivalent of saying

 y = [1 1 1 0 0].*x + [0 0 0 1 1]*7;

Roger Stafford

Subject: A complex mesh grid boundary for plotting

From: Roger Stafford

Date: 7 May, 2008 00:27:03

Message: 7 of 14

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in
message <fvqs6g$ll9$1@fred.mathworks.com>...
> .......
> To make this go the way I think you want, it would have to be written in
this
> fashion:
>
> x = [1 2 3 4 5];
> y = (x<=3).*x + (x>3)*7;
>
> This is the equivalent of saying
>
> y = [1 1 1 0 0].*x + [0 0 0 1 1]*7;
>
> Roger Stafford
---------
  Oops, I meant to write:

 x = [1 2 3 4 5];
 y = (x<=3).*x + (x>3)*(-x);

This is the equivalent of saying

 y = [1 1 1 0 0].*x + [0 0 0 1 1]*(-x);

in the last part.

Roger Stafford

Subject: A complex mesh grid boundary for plotting

From: Roger Stafford

Date: 7 May, 2008 00:59:04

Message: 8 of 14

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in
message <fvqt0n$h7v$1@fred.mathworks.com>...
> Oops, I meant to write:
>
> x = [1 2 3 4 5];
> y = (x<=3).*x + (x>3)*(-x);
>
> This is the equivalent of saying
>
> y = [1 1 1 0 0].*x + [0 0 0 1 1]*(-x);
>
> in the last part.
>
> Roger Stafford
--------
  Oops number two! I left out the dots. It should read:

 x = [1 2 3 4 5];
 y = (x<=3).*x + (x>3).*(-x);

This is the equivalent of saying

 y = [1 1 1 0 0].*x + [0 0 0 1 1].*(-x);

  My apologies.

Roger Stafford

Subject: A complex mesh grid boundary for plotting

From: Steven Lord

Date: 7 May, 2008 03:00:15

Message: 9 of 14


"Bookie via MathKB.com" <u43093@uwe> wrote in message
news:83c4b714bfcb0@uwe...
> Hi,
>
> Yes, I want to say when x is equal to and greater than 'a' but less than
> 'c'
> then y is calculated in a certain way. So yes, if (a <= x) & (x < c);
> describes what I mean as well. I guess this is different from if a <= x <
> c;?

Yes, (a <= x) & (x < c) is different from (a <= x < c). In the latter case,
the expression is evaluated left-to-right, so (a <= x < c) is equivalent to:

(a <= x) < c

I'm going to assume, for sake of argument, that all of a, x, and c are
scalars. [This makes it easier to discuss; it's similar if one or more are
nonscalar.] Now (a <= x) will return either logical 0 or logical 1. If c
is less than 0, the result of (a <= x) < c will always be 0. If c is
greater than 1, the result will always be 1. If c is between 0 and 1, the
result of (a <= x) < c will be the same as (a > x). [If (a<=x) is true or
logical 1, then 1 < c is false or logical 0, and vice versa.]

--
Steve Lord
slord@mathworks.com

Subject: A complex mesh grid boundary for plotting

From: Bookie via MathKB.com

Date: 7 May, 2008 19:15:25

Message: 10 of 14

Thanks Roger, Walter & Steven. I see what you mean. So I've now fixed how
I'm using my relational operators but I'm still not getting x and y inputs
for my function. I've let y = ya + yb, the sum of the y values for each range
of x. ya exists for x between a and c and yb exists for x between c and b.
When one y component does not exist I assume it will return zero for that
component, i.e. for x = b, y = yb. But I've compiled this and I still don't
get my output.

This is what I have:



Roger Stafford wrote:
>"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in
>message <fvqt0n$h7v$1@fred.mathworks.com>...
>> Oops, I meant to write:
>>
>[quoted text clipped - 8 lines]
>>
>> Roger Stafford
>--------
> Oops number two! I left out the dots. It should read:
>
> x = [1 2 3 4 5];
> y = (x<=3).*x + (x>3).*(-x);
>
>This is the equivalent of saying
>
> y = [1 1 1 0 0].*x + [0 0 0 1 1].*(-x);
>
> My apologies.
>
>Roger Stafford

--
Message posted via MathKB.com
http://www.mathkb.com/Uwe/Forums.aspx/matlab/200805/1

Subject: A complex mesh grid boundary for plotting

From: Bookie via MathKB.com

Date: 7 May, 2008 19:18:55

Message: 11 of 14

Sorry here's what I have now that's still not compiling:

% Left out comments and variable declarations, see earlier posting of code
x = a + (ix-1)*(b-a)/(m-1); % a <= x <= b
midXpt1 = c;
% circle1 <= ya <= circle2
ya = (sqrt(r1^2-(((x>=a)&(x<c))-X1)^2)-Y1) + (iy-1).*(-1*sqrt(r2^2-((((x>=a)&
(x<c))-X2)^2)+Y2)-(sqrt(r1^2-(((x>=a)&(x<c))-X1)^2)-Y1))/(n-1);
% m*x+b <= yb <= circle2
yb = (m*((x>=c)&(x<=b))+b) + (iy-1).*((-1*sqrt(r2^2-(((x>=c)&(x<=b))-X2)^2)
+Y2)-(m*((x>=c)&(x<=b))+b))/(n-1);

y = ya + yb;
for i = 1:n
    for j = 1:m
        [T(:,i,j)] = Function(x(i,j),y(i,j));
    end
end
figure
Z = squeeze(T(1,:,:));
surf(x,y,real(Z))
axis tight %want x & y axes tight so curves in x-y plane are not skewed
colormap hsv
colorbar

Bookie wrote:
>Thanks Roger, Walter & Steven. I see what you mean. So I've now fixed how
>I'm using my relational operators but I'm still not getting x and y inputs
>for my function. I've let y = ya + yb, the sum of the y values for each range
>of x. ya exists for x between a and c and yb exists for x between c and b.
>When one y component does not exist I assume it will return zero for that
>component, i.e. for x = b, y = yb. But I've compiled this and I still don't
>get my output.
>
>This is what I have:
>
>>"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in
>>message <fvqt0n$h7v$1@fred.mathworks.com>...
>[quoted text clipped - 16 lines]
>>
>>Roger Stafford

--
Message posted via MathKB.com
http://www.mathkb.com/Uwe/Forums.aspx/matlab/200805/1

Subject: A complex mesh grid boundary for plotting

From: Bookie via MathKB.com

Date: 7 May, 2008 19:21:06

Message: 12 of 14

Forgot some dots! Do I need to put a dot by my division sign?

Bookie wrote:
>Sorry here's what I have now that's still not compiling:
>
>% Left out comments and variable declarations, see earlier posting of code
>x = a + (ix-1)*(b-a)/(m-1); % a <= x <= b
>midXpt1 = c;
>% circle1 <= ya <= circle2
>ya = (sqrt(r1^2-(((x>=a)&(x<c))-X1).^2)-Y1) + (iy-1).*(-1*sqrt(r2^2-((((x>=a)&
>(x<c))-X2).^2)+Y2)-(sqrt(r1^2-(((x>=a)&(x<c))-X1).^2)-Y1))/(n-1);
>% m*x+b <= yb <= circle2
>yb = (m.*((x>=c)&(x<=b))+b) + (iy-1).*((-1*sqrt(r2^2-(((x>=c)&(x<=b))-X2).^2)
>+Y2)-(m.*((x>=c)&(x<=b))+b))/(n-1);
>
>y = ya + yb;
>for i = 1:n
> for j = 1:m
> [T(:,i,j)] = Function(x(i,j),y(i,j));
> end
>end
>figure
>Z = squeeze(T(1,:,:));
>surf(x,y,real(Z))
>axis tight %want x & y axes tight so curves in x-y plane are not skewed
>colormap hsv
>colorbar
>
>>Thanks Roger, Walter & Steven. I see what you mean. So I've now fixed how
>>I'm using my relational operators but I'm still not getting x and y inputs
>[quoted text clipped - 11 lines]
>>>
>>>Roger Stafford

--
Message posted via MathKB.com
http://www.mathkb.com/Uwe/Forums.aspx/matlab/200805/1

Subject: A complex mesh grid boundary for plotting

From: Bookie via MathKB.com

Date: 7 May, 2008 19:22:06

Message: 13 of 14

% Left out comments and variable declarations, see earlier posting of code
x = a + (ix-1)*(b-a)/(m-1); % a <= x <= b
midXpt1 = c;
% circle1 <= ya <= circle2
ya = (sqrt(r1^2-(((x>=a)&(x<c))-X1).^2)-Y1) + (iy-1).*(-1*sqrt(r2^2-((((x>=a)
&
(x<c))-X2).^2)+Y2)-(sqrt(r1^2-(((x>=a)&(x<c))-X1).^2)-Y1))/(n-1);
% m*x+b <= yb <= circle2
yb = (m.*((x>=c)&(x<=b))+b) + (iy-1).*((-1*sqrt(r2^2-(((x>=c)&(x<=b))-X2).^2)
+Y2)-(m.*((x>=c)&(x<=b))+b))/(n-1);

y = ya + yb;
for i = 1:n
   for j = 1:m
       [T(:,i,j)] = Function(x(i,j),y(i,j));
   end
end
figure
Z = squeeze(T(1,:,:));
surf(x,y,real(Z))
axis tight %want x & y axes tight so curves in x-y plane are not skewed
colormap hsv
colorbar




Bookie wrote:
>Forgot some dots! Do I need to put a dot by my division sign?
>
>>Sorry here's what I have now that's still not compiling:
>>
>[quoted text clipped - 26 lines]
>>>>
>>>>Roger Stafford

--
Message posted via MathKB.com
http://www.mathkb.com/Uwe/Forums.aspx/matlab/200805/1

Subject: A complex mesh grid boundary for plotting

From: Bookie via MathKB.com

Date: 12 May, 2008 16:34:04

Message: 14 of 14

Hi,

I've made several modifications to my code but the result is not what I'm
expecting when I compile it. I've placed a simplified version below. I've
checked the logic of my boolean statements. For one range of x values y will
equal ya and for another range of x values y will equal yb. Any advice?

x = a + (ix-1)*(b-a)/(m-1); % a <= x <= b
midXpt1 = c;
% circle1 <= ya <= circle2
ya = (sqrt(r1^2-(((x>=a)&(x<c)).*x-X1).^2)-Y1) + (iy-1).*(-1.*sqrt(r2^2-(((
(x>=a)
&(x<c)).*x-X2).^2)+Y2)-(sqrt(r1^2-(((x>=a)&(x<c)).*x-X1).^2)-Y1))/(n-1);
% m*x+b <= yb <= circle2
yb = (m.*((x>=c)&(x<=b)).*x+b) + (iy-1).*((-1.*sqrt(r2^2-(((x>=c)&(x<=b)).*x-
X2).^2)+Y2)-(m.*((x>=c)&(x<=b)).*x+b))/(n-1);

y = ya + yb;
for i = 1:n
  for j = 1:m
      [T(:,i,j)] = Function(x(i,j),y(i,j));
  end
end
figure
Z = squeeze(T(1,:,:));
surf(x,y,real(Z))
axis tight %want x & y axes tight so curves in x-y plane are not skewed
colormap hsv
colorbar

Thanks!

Walter Roberson wrote:
>>>if a <= x < c;
>
>>if (a <= x) & (x < c)
>
>Ah, I just realized that I wrote that assuming that x was a vector, but
>that if x -is- a vector, then you are going to hit a behaviour
>that you should know about.
>
>If a, c, and x are all single numbers, none of them vectors, then
>
>if a <= x && x < c
>
>is more efficient than using & instead of && .
>
>If x is a vector (more than one element), then the expression
>(a <= x & x < c) will produce a vector of logical results. The
>question then would what you would want to do if some of the results
>were true and some were false. The default in an 'if' statement is
>to only process the 'if' statement if *all* of the values are true.

--
Message posted via MathKB.com
http://www.mathkb.com/Uwe/Forums.aspx/matlab/200805/1

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us