MATLAB: How to connect end points for different series in a line plot

plotting

I have the following code which plots the solution below:
clear all
clc
n = [1 2 3 4 5]; % n = ts/tau
f = @(t_star,y,n) 1-y-(t_star/n); % y = theta* , t_star = t*
for i = 1:length(n)
[t_star,y] = ode45(f,[0 n(i)],0,0,n(i)); %solves ode with n values
figure(1)
line(t_star,y,'color',rand(1,3),'Linewidth',2),grid on
ylabel('\theta*')
xlabel('t*')
ylim([0 1])
end
legend('n=1','n=2','n=3','n=4','n=5')
theta = [0 0.2642 0.297 0.267 0.2271 0.1919];
N = [0 1 2 3 4 5];
figure (2)
plot(N,theta,'Linewidth',2)
I've displayed the data points using the data cursor tool in the figures toolbar. Is there a way to connect these points (make another line) within the same graph?

Best Answer

N = [0,1,2,3,4,5]; % n = ts/tau
Y = zeros(1,numel(N)); % new

C = cell(1,numel(N)); % new
f = @(t_star,y,n) 1-y-(t_star/n); % y = theta* , t_star = t*
for kk = 2:numel(N) % start from 2
[t_star,y] = ode45(f,[0 N(kk)],0,0,N(kk)); %solves ode with n values
line(t_star,y,'color',rand(1,3),'Linewidth',2),grid on
ylabel('\theta*')
xlabel('t*')
ylim([0 1])
% new:
Y(kk) = y(end);
C{kk} = sprintf('n=%u',N(kk));
end
legend(C{:})
hold on
plot(N,Y,'-ok','Linewidth',2)
Giving:
If you want a smoother line, then you will need to curve-fit or interpolate the data, e.g.:
Ni = linspace(N(1),N(end),1000);
Yi = interp1(N,Y,Ni,'pchip');
plot(Ni,Yi,'-k','Linewidth',2)