How do I make surf accurately reflect my data?

Consider this example:
A=zeros(5);
A(3,3)=1;
surf(A)
view(2)
When viewing this, one would be tempted to think that there's a peak at (3.5,3.5) and not at (3,3). Is there a way to make surf (or another function) show the right color exactly where the peak is?
Of course I want to implement this for more complicated data sets, so a general solution would be very nice.

Respuestas (1)

Orion
Orion el 18 de Nov. de 2014
you can play with shading
A=zeros(5);
A(3,3)=1;
surf(A);
pause(1)
view(2);
pause(1)
shading interp

4 comentarios

Henrik
Henrik el 19 de Nov. de 2014
Thanks, this helps. What if I for some reason insist on using shading flat, is there anything to be done then?
other toys
%%CData
figure
A = zeros(5);
A(3,3) = 1;
s = surf(A);
CData = get(s,'CData');
CData(2:3,2:3)=1;
set(s,'CData',CData)
%%bar3
figure
B = zeros(5);
B(3,3) = 1;
b = bar3(B);
Actually using FaceColor=texturemap works here.
A=zeros(5);
A(3,3)=1;
surf(A,'FaceColor','texturemap')
view(2)
What's happening in the FaceColor=flat case is that it's mapping the first 4x4 of the CData to the entire range of XData & YData. It has to do that because a 5x5 grid of XData & YData yields a 4x4 grid of quads.
But with FaceColor=texture, we're mapping the entire 5x5 contents of the CData to the 5x5 range of XData & YData. It can do that because texturemap doesn't have to assign one color per quad. It can split colors across quads so it can do any mapping. You could map a 7x5 CData onto a 3x4 XData & YData if you wanted to. So it gives you a lot of flexibility, but it will also let you make a mess if you're not careful.
Henrik
Henrik el 23 de Nov. de 2014
Thank you Mike, this seems to be exactly what I need. If you post this as an answer I'll accept it.

Iniciar sesión para comentar.

Etiquetas

Preguntada:

el 18 de Nov. de 2014

Comentada:

el 23 de Nov. de 2014

Community Treasure Hunt

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

Start Hunting!

Translated by