Surf plot of edges, smooth on one diagonal, spiky on the other

6 views (last 30 days)
Hey,
I'm using matlab R2013a (32bit, student version) and just came across a problem regarding surf plots. When I plot a simple 10x10 matrix with Z(i,i) = 1, and the neighbouring diagonals 0.5, I receive a nice plot, if I plot the same matrix flipped the resulting edge looks somewhat "spiky" (see images and code below).
Luckily the x-y diagonal is just right for my application of surf, however on another release (2006a) the behaviour is just the other way round, resulting in different diagrams on my collegue's computer.
Is there a way to tell matlab in which direction the diagonals between the datapoints should be filled and in which there might be gaps?
Thanks in advance, best regards, Jan
[X,Y] = meshgrid(1:10);
Z = zeros(10,10);
for ind1 = 1:10
Z(ind1,ind1) = 1;
end
for ind1 = 2:10
Z(ind1,ind1-1) = 0.5;
end
for ind1 = 1:9
Z(ind1,ind1+1) = 0.5;
end
figure
surf(X,Y,Z)
xlabel('X')
ylabel('Y')
figure
surf(X,Y,flipdim(Z,1))
xlabel('X')
ylabel('Y')

Answers (1)

Mike Garrity
Mike Garrity on 23 Oct 2015
What you're seeing is the interpolation scheme I described in this post on the MATLAB Graphics blog. No, you can't control the direction of the split, but that post shows how to use interp2 to use different interpolation methods.
  2 Comments
Malion
Malion on 23 Oct 2015
The problem about interp2 is, that the values are all interpolated using the whole 4point-neighbourhood, why the interpolated data will never reach the value of 1, so even using the interpolation leaves a dip between the peaks.
However, now I understood that there always has to be one "preferred" axis for the interpolation. I'm just lucky, that my data is spread across "the right direction"(at least for my release) (;
Thank you, Mike, for the answer and for making me think further about the interpolation process that has to take place even when one is not using interp2!
Mike Garrity
Mike Garrity on 23 Oct 2015
even using the interpolation leaves a dip between the peaks.
Yes, it depends on the interpolation method. For example, linear is going to create a parabolic hyperboloid for each 2x2 which will give you a set of "saddles" along the ridge.
There are interpolation techniques which are better about preserving these types of narrow features. If you have the Image Processing Toolbox, they have a wide variety of 2D interpolation techniques, and there are a number of helpful people on this forum who can probably help you find a good one for your purposes. It's a particularly interesting field.
As for the interpolation which is built into surface. That one's basically optimized for performance. It's whatever the graphics card thinks is best. As you've noticed, in some versions of MATLAB it can be rather unpredictable. We did some work in R2014b to try and make it behave a bit better, but it can still come up with some surprises.

Sign in to comment.

Categories

Find more on Interpolation 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!