MATLAB: The Plot not showing a line only the points

2-dplotting

I need to show the plot with continous line but it keep plotting only the points, I don't understand the reason .
% Numerical Method of Solving ODE \ Euler Method%
'Example (1)''dy/dx=-y'
dy = @(x,y)-y;
f = @(x)exp(-x);
x0 = 0;
xn = 1;
y = 1;
h = 0.1;
fprintf (' x \t\t y (Euler)\t y(Exact) \n') % data table header
for x = x0 : h : xn-h
y = y + dy(x,y)*h;
x = x + h;
hold on
plot(x,y,'or');
xlabel('X');
ylabel('Y-by Euler method');
hold on
y2 = f(x);
plot(x,y2,'ob')
hold off
fprintf ('%f \t %f\t %f\n',x,y,f(x));
end

Best Answer

At any one time your x and y are scalar. plot() only produces lines when there are at least two adjacent finite points in a single plot call.
You should store all the x and y values and do the plot all at once afterwards.