How to make smoothen 3D surf plot?

6 Ansichten (letzte 30 Tage)
병진
병진 am 12 Apr. 2023
Kommentiert: Sam Chak am 13 Apr. 2023
Hello,
I'm having a surf plot with spikes. I was wondering how i can do to smooth it.
When I search for methods about this problems,
"interp2" function might be a solution. but, I'm having problems with the dimension and did not manage to do so.
  1. I have a matrix (data.GX1) of dimension 60X162 for X values in surf function.
  2. I have a matrix (data.GY1) of dimension 60X162 for Y values in surf fucntion.
  3. I have a matrix (data.Y1) of dimension 60X162 for Z values in surf fucntion.
If possible, I would appreciate it if you could write a code using interp2.
Otherwise, I'd be very glad for some hints on how to do this.
%% Code : Question about "How to smooth surf spikes"
clear ; close all; clc
load('data.mat')
% GX1 = data.GX1; "X values" in struture.
% GY1 = data.GY1; "Y values" in struture.
% Y1 = data.Y1; "Z values" in struture.
%% Define Colormap
fig.colormap = load('Question.mat').Question; % Colormap Name : Question
%% Figure
tp.ax{1,1} = figure(1);
set(tp.ax{1,1},'OuterPosition',[170,140,1600,1000]);
% Plotting : Surf
tp.h1 = surf(data.GX1,data.GY1,(-1)*data.Y1); hold on;
set(tp.h1,'FaceAlpha',1,'Edgecolor','interp','LineStyle','none','Marker','none');
shading interp;
colormap(fig.colormap);
tp.Cb = colorbar;
caxis([-10 16]);
set(tp.Cb,'Ticks',-10:2:16);
tp.Cb.Label.FontSize = 30;
tp.Cb.Label.String = {'Depth variation (cm)'};
axis equal
xlabel('Distance from the center zone (cm)','Fontsize',12);
ylabel('Distance from the center zone (cm)','Fontsize',12);

Akzeptierte Antwort

Mathieu NOE
Mathieu NOE am 12 Apr. 2023
hello
I can make you these two suggestions , one is based on smoothn (see Fex : smoothn - File Exchange - MATLAB Central (mathworks.com), also in attachment) ), the other is using smooth2a (also in attachment)
hope it helps
Result with smoothn
Result with smooth2a
Code
%% Code : Question about "How to smooth surf spikes"
clear ; close all; clc
load('data.mat')
% GX1 = data.GX1; "X values" in struture.
% GY1 = data.GY1; "Y values" in struture.
% Y1 = data.Y1; "Z values" in struture.
X = data.GX1;
Y = data.GY1;
Z = (-1)*data.Y1;
clear data
%% Define Colormap
fig.colormap = load('Question.mat').Question; % Colormap Name : Question
%% Figure
tp.ax{1,1} = figure(1);
set(tp.ax{1,1},'OuterPosition',[170,140,1600,1000]);
% Plotting : Surf
tp.h1 = surf(X,Y,Z);
set(tp.h1,'FaceAlpha',1,'Edgecolor','interp','LineStyle','none','Marker','none');
shading interp;
colormap(fig.colormap);
tp.Cb = colorbar;
caxis([-10 16]);
set(tp.Cb,'Ticks',-10:2:16);
tp.Cb.Label.FontSize = 30;
tp.Cb.Label.String = {'Depth variation (cm)'};
axis equal
xlabel('Distance from the center zone (cm)','Fontsize',12);
ylabel('Distance from the center zone (cm)','Fontsize',12);
%% Figure 2 (smoothn)
s_factor = 1; % smoothing parameter
Zs = smoothn(Z,s_factor,'robust'); % FEX : https://fr.mathworks.com/matlabcentral/fileexchange/25634-smoothn/
tp.ax{1,1} = figure(2);
set(tp.ax{1,1},'OuterPosition',[170,140,1600,1000]);
% Plotting : Surf
tp.h1 = surf(X,Y,Zs);
set(tp.h1,'FaceAlpha',1,'Edgecolor','interp','LineStyle','none','Marker','none');
shading interp;
colormap(fig.colormap);
tp.Cb = colorbar;
caxis([-10 16]);
set(tp.Cb,'Ticks',-10:2:16);
tp.Cb.Label.FontSize = 30;
tp.Cb.Label.String = {'Depth variation (cm)'};
axis equal
xlabel('Distance from the center zone (cm)','Fontsize',12);
ylabel('Distance from the center zone (cm)','Fontsize',12);
%% Figure 3 (smooth2a)
ZZ = smooth2a(Z,3,3);
tp.ax{1,1} = figure(3);
set(tp.ax{1,1},'OuterPosition',[170,140,1600,1000]);
% Plotting : Surf
tp.h1 = surf(X,Y,ZZ);
set(tp.h1,'FaceAlpha',1,'Edgecolor','interp','LineStyle','none','Marker','none');
shading interp;
colormap(fig.colormap);
tp.Cb = colorbar;
caxis([-10 16]);
set(tp.Cb,'Ticks',-10:2:16);
tp.Cb.Label.FontSize = 30;
tp.Cb.Label.String = {'Depth variation (cm)'};
axis equal
xlabel('Distance from the center zone (cm)','Fontsize',12);
ylabel('Distance from the center zone (cm)','Fontsize',12);
  2 Kommentare
병진
병진 am 13 Apr. 2023
Thank you,
I think this method is the perfect answer for me.
Again, thank you for your reply.
Sam Chak
Sam Chak am 13 Apr. 2023
@병진, Don't forget to accept the helpful perfect answer.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Line Plots finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by