# Mesh and Surf graphics problem

3 views (last 30 days)
Dominik Jerinic on 4 Mar 2022
Commented: Dominik Jerinic on 5 Mar 2022
Hi guys,
I have a problem to display my results in 3D graphics. When I am using MESH function for 2D graphics, results are correct according to values in table. When using SURF function for 3D graphics, I got some extra areas that shouldnt be shown because values are all zero (0) for that areas. Check lower description for details.
Methodology:
Values are shown in table "sesti_sloj" in attachement. To show 2D graphics, I am using mesh function mesh(1:360, 1:180, sesti_sloj). To show 3D graphics, I am using code as follows:
n=1;
for i=1:360
for j=1:90
n=n+1;
end
end
x_int = linspace(min(x),max(x), 200);
y_int = linspace(min(y),max(y), 200);
[X, Y] = meshgrid(x_int,y_int);
Z = griddata(x,y,z, X,Y, 'nearest');
surf(X,Y,Z)
n=1;
for i=1:360
for j=91:180
n=n+1;
end
end
x_int = linspace(min(x),max(x), 200);
y_int = linspace(min(y),max(y), 200);
[X, Y] = meshgrid(x_int,y_int);
Z = griddata(x,y,z, X,Y, 'nearest');
hold on
surf(X,Y,Z)
I f you check 2D and 3D graphics, you will see some differences that are product of some error I dont understand. For example, check "wings" in 3D graphics on the sides of smaller half-sphere part of graphics. They do not exist in 2D graphics and also those values are all zero (0) in table "sesti_sloj".
Please check if you can help.

Simon Chan on 5 Mar 2022
You redo the meshgrid and re-sample the data via griddata may be the cause of your problem.
Just remove all additional meshgrid and griddata codes is able to generate the 3D plot easily.
for i=1:360
for j=1:90
end
end
s1=surf(x,y,z);
s1.EdgeColor = 'none';
hold on
for i=1:360
for j=91:180
end
end
s2 = surf(x,y,z);
s2.EdgeColor = 'none'; Dominik Jerinic on 5 Mar 2022
Sorry but this is wrong. y cannot be outside 1:180 so upper solutions are much closer to the right one. I have to just make this upper and lower fins smother because there shouldnt be any steep "hils" on the graphics.