How do i smooth a plot?

조회 수: 1 (최근 30일)
Slarn
Slarn 2014년 1월 26일
편집: Image Analyst 2014년 2월 28일
figure
plot(delta(90:840,485),'XData',[0:(D*1000)/750:(D*1000)]); %plot line y 485
smooth(delta(90:840,485),'XData',[0:(D*1000)/750:(D*1000)],loess);
xlabel('Distance(mm)');
ylabel('Delta');
figure_FontSize=13;
set(get(gca,'XLabel'),'FontSize',figure_FontSize,'Vertical','top');
set(get(gca,'YLabel'),'FontSize',figure_FontSize,'Vertical','middle');
set(findobj('FontSize',10),'FontSize',figure_FontSize);
set(gca,'tickdir','in')
set(gca,'ticklength',[0.01 0.01]);
axis on
I tried the matlab help but i cant seem to get it right :( attached is the plot i obtained
  댓글 수: 1
Image Analyst
Image Analyst 2014년 1월 26일
Upload your delta and D coordinates if you want us to help with your actual data.

댓글을 달려면 로그인하십시오.

답변 (4개)

vijay sai
vijay sai 2014년 1월 26일
try varying the range of the axes ...i.e. suppose if distance axes is given the range 0:1:10.. try doing this way 0:0.1:10..may be it could solve the issue...
  댓글 수: 2
Slarn
Slarn 2014년 1월 26일
May i know how to write it in code form?
vijay sai
vijay sai 2014년 1월 26일
편집: Walter Roberson 2014년 1월 27일
am trying to show u a simple example..my answer just based upon the assuming that no of samples u take to plot the figure effect the results..so i am showing you the simple code of plotting a sine wave..so if my view of the problem is relevant to yours...alter the no of samples..
clc
close all
clear all
t=0:0.4:10;
f=1;
x=sin(2*pi*f*t);
figure
plot(t,x)
t1=0:0.1:10;
f=1;
y=sin(2*pi*f*t1);
figure
plot(t1,y)
t2=0:0.001:10;
f=1;
y=sin(2*pi*f*t2);
figure
plot(t2,y)

댓글을 달려면 로그인하십시오.


Walter Roberson
Walter Roberson 2014년 1월 26일
You could pass the Y values through a moving average filter or other low-pass filter before plotting.
You could take the existing Y values and use a spline fit between them and then interpolate at a higher resolution time scale and plot that -- but you would probably not see much of a difference unless you zoomed in.
  댓글 수: 1
Walter Roberson
Walter Roberson 2014년 1월 27일
Change your line
plot(delta(90:840,485),'XData',[0:(D*1000)/750:(D*1000)]);
to
XData = [0:(D*1000)/750:(D*1000)];
rawYData = delta(90:840,485);
YData = conv(rawYData, ones(1,25)); %sliding mean
plot(XData, YData);

댓글을 달려면 로그인하십시오.


Image Analyst
Image Analyst 2014년 1월 26일
편집: Image Analyst 2014년 2월 28일
Lots of ways. Various filters.
smoothY = conv(y, ones(1,25)); % Sliding mean
smoothY = medfilt1(y, 11); % 1D median filter
% Savitzky-Golay sliding polynomial filter
smoothY = sgolayfilt(y, polynomialOrder, windowWidth);
and others like wiener, etc.

Slarn
Slarn 2014년 1월 27일
i cant seem to smooth my 2 figures with the moving average. not sure what went wrong. attached is the files
  댓글 수: 1
Image Analyst
Image Analyst 2014년 1월 27일
Looks like Walter's code should work. Did you try it?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Smoothing and Denoising에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by