How to smoothen a plot?
1 回表示 (過去 30 日間)
古いコメントを表示
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1038350/image.jpeg)
how do I smoothen the plot and get rid of the vertical lines?
2 件のコメント
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
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:
0 件のコメント
その他の回答 (1 件)
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.
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!