How to raise one 'box' up or down by 0.5?

Hi everyone,
I have a simple question. If I have a simple surface plot (surf(peaks)), then is it possible for me to 'raise' or 'push down' each individual 'grid boxes' up or down by a certain amount of z?
Thank you

Answers (1)

z = peaks;
idx1 = some list of locations
z(idx1) = z(idx1) - 0.5;
idx2 = some other list of locations
z(idx2) = z(idx2) + 0.5;

7 Comments

Thanks. How do I give those list of locations as?
If you have a list of row and corresponding columns then you can use sub2ind() to convert the row/column pairs into the indices suitable for use in the above syntax.
If you are manipulating lines or blocks in Z then you can give the coordinates directly, such as
z(2:end-1, 20:43) = z(2:end-1, 20:43) - 0.5;
Can I give x and y coordinates instead?
No. But you can convert the x and y to indices
xidx = interp1(xcoord_vector, 1:length(xcoord_vector), x_to_move, 'nearest');
yidx = interp1(ycoord_vector, 1:length(ycoord_vector), y_to_move, 'nearest');
idx = sub2ind(size(z), yidx, xidx); %note this is Y X
Here xcoord_vector is the list of x coordinates for the full plot and x_to_move is the x coordinates of the points you want to shift the z of. Likewise for the corresponding y variable.
Hi Walter,
I still can't seem to get a hold of this. I'm getting plenty of errors. I would appreciate if you could use the example below.
the example below, I want the 'gridbox' between x = -1 to -1.5 and y = -1 to -1.5 raised by 2 units on the z axis? this will make just that one gridbox higher than the rest of the surface.
Here's the sample:
x = [-2:.5:2];
y = [-2:.5:2];
Test = @(x,y)x + y;
[X,Y] = meshgrid(x,y);
Z1 = Test(X,Y);
s1 = surf(X,Y,Z1);
If you want a grid box to be raised in a disconnected manner, then you cannot use surf() and instead will need to use patch().
You could construct the sections independently, tracing along the edges of the contiguous regions.
Or you can take advantage of the fact that seconds will not be drawn if you use NaN as the corresponding value or coordinate, and so construct a grid structure with NaN in the place you want to cut out and then construct an additional region for where you want to be raised.
Now that I think of it, you could get away with using three surf(). The main surf would have nan for the Z values of the places you want to cut out. Then "hold on" and draw a second surf that has a higher Z for the places you want raised and NaN everywhere else, and then a third surf that has a lower Z for the places you want recessed and NaN everywhere else.
I like your third idea. Would you be able to help me with it? How can I assign NaN to above mentioned values?

This question is closed.

Tags

Asked:

A
A
on 19 Oct 2015

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!