How can I smoothen my plots by removing sharp edges/points in the plots?

9 ビュー (過去 30 日間)
Comfort Sekga
Comfort Sekga 2024 年 10 月 12 日
コメント済み: Star Strider 2024 年 10 月 12 日
I have two codes for generating plots given below. The first code generate a plot from the data file attached. I need help to remove sharp edges/points that appear on the plots so that I get smooth curves. Below is the first code;
A=load('dataQ0.05t.txt');
y = A(:,2);
x = A(:,1);
plot(x,y,'b')
semilogx(x,y,'b')
The second code;
r = linspace(10^-2,10^2);
eta=zeros(size(r));
%hold on;
for delta= [0 1 2 3 4 5 6]
for k=1:numel(r)
f=@(x,y) (1./pi).*(x.*exp(-3.44.*r(k).^(5/3).*x.*(sin(y/2)).^(5/3)).*cos(delta*y));
eta(k) = integral2(f,0,1,0,2*pi).*exp(-10);
% hold on
end
plot(r,eta)
axis([10^(-0.5) 10^2 10.^(-9) 10.^(-4)])
loglog(r,eta)
hold on
end

採用された回答

Star Strider
Star Strider 2024 年 10 月 12 日
編集済み: Star Strider 2024 年 10 月 12 日
One option is to use vectors with increased resolutiuon (numbers of points), and then interpolate as necessary —
A=load('dataQ0.05t.txt');
y = A(:,2);
x = A(:,1);
plot(x,y,'b')
semilogx(x,y,'b')
xi = linspace(min(x), max(x), 250).';
yi = interp1(x, y, xi);
figure
semilogx(xi, yi, 'b')
title('Increased Resolution, Interpolated')
% r = linspace(10^-2,10^2);
r = logspace(-2, 2, 100);
eta=zeros(size(r));
%hold on;
for delta= [0 1 2 3 4 5 6]
for k=1:numel(r)
f=@(x,y) (1./pi).*(x.*exp(-3.44.*r(k).^(5/3).*x.*(sin(y/2)).^(5/3)).*cos(delta*y));
eta(k) = integral2(f,0,1,0,2*pi).*exp(-10);
% hold on
end
plot(r,eta)
axis([10^(-0.5) 10^2 10.^(-9) 10.^(-4)])
loglog(r,eta)
hold on
end
title('Using ‘logspace’ With Increased Resolution')
The second plot uses the logspace function with 100 points to create much smoother curves.
.
  4 件のコメント
Comfort Sekga
Comfort Sekga 2024 年 10 月 12 日
@Star Strider Thank you very much. The plot looks good now.
Star Strider
Star Strider 2024 年 10 月 12 日
As always, my pleasure!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by