Convert these lines to Curves

3 views (last 30 days)
Maduka
Maduka on 23 Dec 2022
Commented: Fabio Freschi on 23 Dec 2022
N = [5:5:10 20:30:80];
t = (0:0.2:1).';
U = [0 0 0 0 0;
-0.203 -0.2045 -0.2094 -0.2248 -0.2411;
-0.8334 -0.8742 -0.9593 -1.2573 -1.6266;
-1.9722 -2.1899 -2.6840 -4.737 -7.9306;
-3.7592 -4.51 -6.3789 -16.1119 -35.5583;
-6.4136 -8.4597 -14.1636 -52.4222 -148.671];
hp = plot(t,U,'-');
lstr = cell(numel(N),1);
title('Effect of Radiation on Velocity')
for k = 1:numel(N)
lstr{k} = sprintf('N = %d',N(k));
end
legend(hp,lstr,'location','southwest')
Please I need assistance in converting the lines to curves

Answers (1)

Fabio Freschi
Fabio Freschi on 23 Dec 2022
Edited: Fabio Freschi on 23 Dec 2022
You can interpolate your data using interp1.
Warning: the interpolation may be not accurate for your trend, in this case is only an "educated guess".
clear variables, close all
N = [5:5:10 20:30:80];
t = (0:0.2:1).';
U = [0 0 0 0 0;
-0.203 -0.2045 -0.2094 -0.2248 -0.2411;
-0.8334 -0.8742 -0.9593 -1.2573 -1.6266;
-1.9722 -2.1899 -2.6840 -4.737 -7.9306;
-3.7592 -4.51 -6.3789 -16.1119 -35.5583;
-6.4136 -8.4597 -14.1636 -52.4222 -148.671];
figure, hold on
hp = plot(t,U,'o');
title('Effect of Radiation on Velocity')
% use a finer sampling of t vector
tint = (0:0.02:1);
% interpolate
Uint = interp1(t,U,tint,'pchip');
% restart color order
set(gca,'ColorOrderIndex',1);
% plot
hp = plot(tint,Uint,'-');
% legend
lstr = arrayfun(@(x)['N = ',num2str(x)],N,'UniformOutput',false);
legend(hp,lstr,'location','southwest')
  2 Comments
Maduka
Maduka on 23 Dec 2022
Thanks, I appreciate, can I remove those markers?
Fabio Freschi
Fabio Freschi on 23 Dec 2022
simply comment out the first plot

Sign in to comment.

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Products


Release

R2014a

Community Treasure Hunt

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

Start Hunting!