How to find when a surface deviates from other surface(s)
Show older comments
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)
Star Strider
on 18 Apr 2014
Edited: Star Strider
on 18 Apr 2014
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
A
on 18 Apr 2014
Star Strider
on 18 Apr 2014
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!
A
on 18 Apr 2014
Star Strider
on 18 Apr 2014
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.
Walter Roberson
on 18 Apr 2014
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.
Star Strider
on 18 Apr 2014
Thank you. I just looked at it, and didn’t analyse it in detail.
Star Strider
on 18 Apr 2014
Edited: Star Strider
on 18 Apr 2014
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!
A
on 18 Apr 2014
Star Strider
on 18 Apr 2014
I believe that would be where OfInterest = 1.
A
on 19 Apr 2014
Star Strider
on 19 Apr 2014
[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.
Categories
Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!