How to find when a surface deviates from other surface(s)

Hi guys,
I have 3 surfaces. I want to find out values for x and y, where each of the three surfaces deviates from the other two by more than 0.5 value on the z axis. Is this a simple enough thing?
I can imagine it being super easy to do with only two surfaces because you could just substract one from the other. But how do I do it with 3 surfaces? Any ideas?
Ideally, I'd like to see [x,y] points for each surface where it deviates from other surfaces on z-axis by > 0.5.
It would be great to be able to graphically see this 'deviation' as well perhaps as another surface?
A member on the forum recommended the following method, however my inexperience with matlab means that I'm not sure how to interpret the logical array and/or see it as a plotted surface.
>> x = [-10:10];
>> y = [-10:10];
>> test1 = x + 0.5*y;
>> test2 = x + y;
>> test3 = x + 1.5*y;
>> testI = meshgrid(test1);
>> testII = meshgrid(test2);
>> testIII = meshgrid(test3);
>> surf(x,y,testI);
>> hold on
>> surf(x,y,testII);
>> surf(x,y,testIII);
*>> OfInterest = any(diff( sort( cat(3, test1, test2, test3), 3), 3) > 0.5, 3);*
>> OfInterest
OfInterest =
Columns 1 through 15
0 0 0 0 0 0 0 0 1 1 0 0 0 0 0
Columns 16 through 18
0 0 0
>> image(OfInterest);
>> colormap(gray(2));
Thanks

Answers (1)

Does this do what you want?
x = -10:10;
[X,Y] = meshgrid(x);
test1 = X + 0.5.*Y;
test2 = X + Y;
test3 = X + 1.5.*Y;
figure(1)
surfc(X,Y,test1)
hold on
surf(X,Y,test2)
surf(X,Y,test3)
hold off
% ‘OfInterest’ -> Walter Roberson (http://www.mathworks.com/matlabcentral/answers/125901-how-to-find-when-a-surface-deviates-from-other-surface-s)
OfInterest = any(diff( sort( cat(3, test1, test2, test3), 3), 3) > 0.5, 3);
D = zeros(size(X));
D(1:size(OfInterest,1), 1:size(OfInterest,2)) = OfInterest(1:end,1:end);
figure(2)
surfc(X, Y, D)

12 Comments

I think so.. maybe.
Could you please explain what the OfIntnerest and D = is doing?
And then.. what exactly is the surface showing?
Thank you for this
I’ll let Walter explain ‘OfInterest’, although if you read the documentation on cat, sort, diff, and any, you can figure it out yourself.
D simply creates a matrix of appropriate dimensions to plot against X and Y. ‘OfInterest’ isn’t of the correct dimensions on its own to do that.
The surface in figure(1) shows your three functions, test1, test2, and test3 plotted together on the same axes. If you rotate the plot in the figure window, you can see them as individual intersecting planes. The surface in figure(2) is a plot of OfInterest, since you asked to see it as a plotted surface.
My pleasure!
I understand figure 1 and the individual plots of my test functions.
However, I don't quite understand figure2. How can I know from that figure that test 1 (or test 2 or 3) deviates by more than 0.5 at a certain x,y?
The second figure is simply a plot of Walter’s ‘OfInterest’ statement. It first concatenates your test1, test2, test3 arrays along the z dimension, then sorts them in ascending order along that dimension, takes the difference, and tests if any of that array are >0.5, again in the z dimension. [It seems to do the opposite of what you want (and the plot should then be inverted), but perhaps I’m not reading OfInterest correctly.] OfInterest creates a logical array, so the difference is either >0.5, or not. Note that OfInterest considers all three functions together, and (as I read it) doesn’t give pair-wise differences.
A point is of interest if it has a deviation larger than 0.5.
The code uses transitive comparisons. If A, B, and C are in increasing sorted order then if the A to B difference is more than 0.5 then the A to C difference is also going to be more than 0.5; if the A to B difference is less than 0.5 then the lowest surface was within the deviation distance of at least one of the other surfaces and so the distance between those two surfaces is not of interest. Apply the same logic for the B to C distance. Similarly if A to B is within 0.5 and B to C is within 0.5 then it does not matter that A to C might be more than 0.5 as each of the surfaces would be within 0.5 of at least one of the other surfaces.
If the question is whether there is a surface further than 0.5 from some other surface (rather than whether there is a surface further than 0.5 from both other surfaces) then the code change would no be all that big.
Thank you. I just looked at it, and didn’t analyse it in detail.
A
A on 18 Apr 2014
Edited: A on 18 Apr 2014
So, is there a way for me to find out that:
Test 1 deviates by > 0.5z from test 2 AND/ test 3 at: [10, 41], [14,51], [16, 21], etc.?
And then somehow see this 'deviation' in a graphic format? I know the second figure does this, but I have no idea what's going on in it when it goes from 0 to 1?
Thanks so much, and sorry to ask so much.
As I read Walter’s comment, his OfInterest line does exactly that. If you want to test it at specific points, simply reference it as:
OfInterest(10,41)
for example.
My pleasure!
And how can I get it to give me a list all points where the deviation > 0.5 happens?
Thanks
I believe that would be where OfInterest = 1.
So would there be a way to ask MatLab to please print or give [x,y] wherever OfInterest = 1?
Sorry I don't know enough Matlab code to do this. If this was Java, I'd say something like:
if(OfInterest = 1) { system.printout([x,y]); }
lol.
Probably the easiest way is to use the find function:
[r,c] = find(OfInterest == 1);
This will give you the row- and column-indices of the elements of OfInterest that are equal to 1. You can then use them to identify the corresponding values of X and Y.

Sign in to comment.

Categories

Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange

Asked:

A
A
on 18 Apr 2014

Commented:

on 19 Apr 2014

Community Treasure Hunt

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

Start Hunting!