Complex question: Want to find [x,y] when z > 0.5 from z of other surfaces.

For instance, I have three basic surface plots:
x = [-10:10]; y = [-10:10]; test1 = x + 0.5*y; test2 = x + y; test3 = x + 1.5*y;
Which equate to:
test1 =
Columns 1 through 9
-15.0000 -13.5000 -12.0000...
test2 =
Columns 1 through 9
-20 -18 -16...
test3 =
Columns 1 through 13
-25.0000 -22.5000 -20.0000...
Goal: I want to find out [x,y] when test2 deviates from test1 AND test3 by > 4.5.
So in the example above, I would want to know the [x,y] when test2 = -20, because clearly it is when test2 deviates from test1 AND test3 by > 4.5.
(i.e., column1 in all three equations is where absolutevalue(-20-(-15)) AND absolutevalue(-20-(-25) is > 4.5; so I want to know at what [x,y] this occurs)
Thank you!

 Accepted Answer

This works:
x = [-10:10];
y = [-10:10];
test1 = @(x,y) x + 0.5*y;
test2 = @(x,y) x + y;
test3 = @(x,y) x + 1.5*y;
[X,Y] = meshgrid(x,y);
T1 = test1(X,Y); % Generate surfaces
T2 = test2(X,Y);
T3 = test3(X,Y);
D = (abs(T2-T1)+abs(T2-T3)) > 4.5; % Differences
[Dr,Dc] = find(D); % Indices where D == 1
figure(1)
surf(X,Y,T1)
hold on
surf(X,Y,T2)
surf(X,Y,T3)
hold off
grid on
figure(2)
surf(X, Y, double(D))

8 Comments

Dear Star Strider,
That is PERFECT!! just what I wanted.
Just one question:
Do you think this:
D = (abs(T2-T1)+abs(T2-T3)) > 4.5; % Differences
Can somehow become this:
D = (abs(T2-T1) && abs(T2-T3)) > 4.5; % Differences
Because I want T2-T1 to be > 4.5 AND I want T2-T3 > 4.5; not the summation of them?
Would I need an if statement?
Thanks
x = [-10:10];
y = [-10:10];
test1 = @(x,y) x + 0.5*y;
test2 = @(x,y) x + y;
test3 = @(x,y) x + 1.5*y;
[X,Y] = meshgrid(x,y);
T1 = test1(X,Y); % Generate surfaces
T2 = test2(X,Y);
T3 = test3(X,Y);
*D = (abs(T2-T1) > 4.5) & (abs(T2-T3) > 4.5); % Differences*
[Dr,Dc] = find(D); % Indices where D == 1
figure(1)
surf(X,Y,T1)
hold on
surf(X,Y,T2)
surf(X,Y,T3)
hold off
grid on
figure(2)
surf(X, Y, double(D))
How about this? I think this works.
Please mark his answer as Accepted then.
A — Your restatement for D will do what you want.
Image Analyst — Thank you!
Hi Star Strider,
I hope you are well. I had a follow-up question and request for help.
Presently, the graph I get is binary. I can find out areas where z is > 4.5 (denoted by 1) and areas where it isn't > 4.5 (denoted by 0).
Is it possible to find out the actual difference instead of getting a binary value of 1 or 0? So I want to only find values that are > 4.5, but it's find if they remain 0 where it is < 4.5?
Does this make sense what I'm asking for?
Thank you
II’m not certain I understand.
However if you want to find the actual differences rather than the logical test for the threshold, simply remove the threshold condition and other logical operators. So D becomes:
D = (abs(T2-T1)+abs(T2-T3));
It now returns a double result and will be plotted in figure(2) as a continuous surface. The rest of the code remains the same.
Thank you! I think that works. I used that in combination with the min() function to get it working.

Sign in to comment.

More Answers (0)

Asked:

A
A
on 30 Apr 2014

Commented:

on 24 May 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!