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

9 views (last 30 days)
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

Accepted Answer

Star Strider
Star Strider on 12 Oct 2024
Edited: Star Strider on 12 Oct 2024
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 Comments

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!