How do I get rid of lines on a surf command? Also how do I change the surf to green rather than the default gradient colours?

I am doing my University dissertation and I want rid of the lines that appear on the surface created by the surf command 'surf(xp,yp,zp)'. I have tried 'LinesVisible = FLASE' but it keeps coming up saying that the '=' is not correct. I also want to turn the surface of this plot to green.
Any help would be amazing. Am not the best on Matlab. I can send my code if that helps anyone.
Thanks Grant

 Accepted Answer

Yes, but you should realize that 'LinesVisible = FLASE' (despite the misspelling of false) is not even standard syntax in MATLAB for property/value pairs. So you might spend some time familiarizing yourself with that syntax.
You might try the property/value pair: 'edgecolor','none'
I think that is the proper one to kill the lines. Or you can be completely lazy, and just do what I do. So use the command
shading interp
which kills off the lines. Of course, it also causes the shading to be smoother, since it is now interpolated.
If you want the surface to be green, you can use a colormap that will give you shades of green.
surf(peaks(20))
colormap summer
shading interp
Or, you can just set the color to be a boring, flat, greenish hue.
h = surf(peaks(50));
set(h,'edgecolor','none','facecolor',[.1 .9 .1])
I would guess that this would usually not make people happy, since it is difficult to visualize the shape. Those edges really do help on a mono-color surface.
set(h,'edgecolor','r','facecolor',[.1 .9 .1])

7 Comments

The 'Shading interp' works but I cant get the 'h' to work. Will I need to get the h to work before I can add lighting? I keep getting this message
Error using set
Invalid property found.
Object Name: surface
Property Name: 'edgecolour'.
Error in veiitchalgebra (line 66)
set(h,'edgecolour','r','facecolor',[.1 .9 .1])
MATLAB SHOULD be smart enough, and recognize those miss-spellings without just getting upset. After all, a large population does spell color as colour. One day they will learn. Or maybe we will. :)
Of course, you could just be lazy, and use the property 'edgecol'. MATLAB does recognize contractions, even if you WOULD have spelled the rest of the word "wrongly".
Oh right i see, Yeah that works now. Is there a way to spread out the edge lines if in the end i dont get rid of them? At the minuet they are very close together. Or is it just because of the equation I am using?
MATLAB automatically puts a line at every edge in the surface. The problem is, this tends to over do it for some surfaces with a fine spacing. It would be nice if we could simply tell it to plot every k'th edge in a surface. I don't think that is an option, unless they have added it since last I looked.
So one option is to plot the surface using a colormap as I showed first. Then no lines at all are really needed.
You could also plot the surface as a single colored (ok, if you insist, coloured) surface with no edges, then using hold on, add only the edges you wish to have plotted. You could plot those edges using any of a variety of tools, so mesh, surf, plot, line, etc.
As an intermediate solution: I noticed that if you still want the edges - just not so pronounced that they polute your image too much - then you could also reduce the edge thickness by useing a property combination like:
set(h, 'EdgeAlpha',0.3)

Sign in to comment.

More Answers (3)

It seems to me that you're guessing the syntax here. Better go through the handles.
h = surf(xp,yp,zp)
get(h)
gives you all the attribute of your surface.
You want linestyle and color
set(h,'linestyle','none','facecolor',[0 .7 0]);
and add some light
light

6 Comments

Oh, if you have a recent version of matlab, I think you can also go like
h.linestyle='none';
h.color = [0 .7 0];
That still doesnt seam to work. This is my code if it helps...
clear all
clc
L = 15
A = 10
syms z y x xdot ydot zdot xddot yddot zddot lam a b c g real
f = A*cos(x/L)*sin(y/L) -z
G = A*cos(x/L)*sin(y/L)
fx = diff(f,x)
fy = diff(f,y)
fz = diff(f,z)
fdot = fx*xdot + fy*ydot + fz*zdot
fxx = diff(fx,x)
fxy = diff(fx,y)
fxz = diff(fx,z)
fyx = diff(fy,x)
fyy = diff(fy,y)
fyz = diff(fy,z)
fzx = diff(fz,x)
fzy = diff(fz,y)
fzz = diff(fz,z)
W = [fxx fxy fxz; fyx fyy fyz; fzx fzy fzz]
ftt = [xdot ydot zdot]*W*[xdot ydot zdot]' + [fx fy fz]*[xddot yddot zddot]'
Eqx = xddot - lam*fx
Eqy = yddot - lam*fy
Eqz = zddot - lam*fz -g
Eqf = ftt
sol = solve(Eqx,Eqy,Eqz,Eqf,xddot,yddot,zddot,lam)
for i = 1 :165
for j = 1:165
x = (i-5);
y = (j-5);
z = A*cos(x/L)*sin(y/L);
xp(i,j) = x;
yp(i,j) = y;
zp(i,j) = z;
end
end
h = surf(xp,yp,zp)
get(h)
set('linestyle','none','color',[0 .7 0]);
axis([-25 150 -25 150 -25 100])
axis square
xlabel('Displacement along the x-axis (m)')
ylabel('Displacement along the y-axis (m)')
zlabel('Displacement along the z-axis (m)')
hold on
Sorry, my bad. It's
set(h,'property', 'value')
not
set('property','value')
you should do something to format your code so that it's readable. There is a button "{}code"
Also, I suggest to use ; at the end of your instructions. Defining the vectors x,y,z wouldn't hurt either;
"Doc surf" provides the documentation. At the bottom you can find out how to customize the surface.
ok, again my bad. Apologies,
it should be
set(h,'facecolor',[0 .6 0],'linestyle','none')
Do not forget the instruction for light
light
And the instruction get(h) is just for you to look at the attribute you can change. It does not do anything else but displaying all of them.
Is there a way to get the light to stay coming in from one side even if I rotate the viewing angle of the surface?
Interesting... I'm not sure. Perhaps "camlight" instead of "light". Take a look into the documentation "doc camlight"

Sign in to comment.

Matlab (and Octave) work faster if the 2D mesh array is pre-allocated. This is typically done by M = zeros(nrows,ncols). I found the grid lines annoying and removed them by preallocating with M = 0.01*ones(nrow,ncols) to remove any zero values that seem to cause the problem.

Community Treasure Hunt

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

Start Hunting!