How to smoothen a plot?

조회 수: 1 (최근 30일)
DARSHAN KUMAR BISWAS
DARSHAN KUMAR BISWAS 2022년 6월 19일
댓글: Image Analyst 2022년 6월 19일
a=imread('IMG_0.jpg');
b=imread('IMG_20.jpg');
c=a(:,:,3)-b(:,:,3);
max(max(c));
min(min(c));
no_row=size(c,1);
no_col=size(c,2);
k=zeros(1,4857);
y=linspace(0,200,200);
l=zeros(45,200);
for m=1:45
for n=1:200
l(m,n)=mean(mean(c(((m-1)*10+1):10*m,((n-1)*24+1):24*n)));
end
end
o=zeros(1,200);
for i=1:200
p=l(:,i);
for j=1:45
if p(j)>=100
o(i)=j;
plot(y,(45-o)*20/45)
break
end
end
end
how do I smoothen the plot and get rid of the vertical lines?
  댓글 수: 2
DARSHAN KUMAR BISWAS
DARSHAN KUMAR BISWAS 2022년 6월 19일
Please keep in ming that I am a begineer and before matlab I have done work only in C loanguage.
Image Analyst
Image Analyst 2022년 6월 19일
Yes, most people here are beginners. But that doesn't mean you cannot understand a direct request to attach your data? Anyone can understand that even if they don't know MATLAB programming. Just use the paperclip icon to attach a text file with the x and y data in it. Not sure what those two images you read in are, but go ahead and attach those two images just in case it helps explain something.

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

채택된 답변

Image Analyst
Image Analyst 2022년 6월 19일
Try this (untested because you forgot to attach your data). Also it depends if you want to delete the bad points or it you want to change them to interpolated/repaired values.
% To remove bad elements:
badIndexes = y > y(end);
x(badIndexes) = [];
y(badIndexes) = [];
% Alternatively to leave them there but replace them with a quadratic fit:
goodIndexes = (y <= y(end)); % A logical vector.
% Now fit a quadratic to just the good values.
coefficients = polyfit(x(goodIndexes), y(goodIndexes), 2);
% Now get a fitted y.
yFixed = polyval(coefficients, x);
% Replace bad y values with fixed/repaired/interpolated ones.
y(~goodIndexes) = yFixed(~goodIndexes);
If you have any more questions, then attach your data and code to read it in with the paperclip icon after you read this:

추가 답변 (1개)

John D'Errico
John D'Errico 2022년 6월 19일
편집: John D'Errico 2022년 6월 19일
Simple. Delete the points in the beginning of the curve that give you the spikes. WTP? They will be easy enough to spot, as they will have an unreasonably large y value compared to the rest.
If the result is STILL too noisy, then use smooth on it. Or appy a smoothing spline, if you hve the curve fitting toolbox. Or, to be honest, the remaining curve looks almost well enough behaved that you could fit it with a low order polynomial. You can do that using polyfit, or with the stats toolbox or the curve fitting toolbox. You might prefer the results from a robustfit, which will be than from a simple least squares fit, given the somewhat spiky data.
If you want a better answer, then you would need to attach a copy of your data to a comment, or by editting your original question.

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by