why won't this plot?

1 view (last 30 days)
Don on 4 Oct 2016
Commented: Don on 4 Oct 2016
for i = 1:length(xaxis); if xaxis(i) >0; plot(xaxis(i),yaxis(i)); end
end;
xaxis and yaxis have numbers. I always get a blank plot space

Steven Lord on 4 Oct 2016
% Sample data
xaxis = -2*pi:0.1:2*pi;
yaxis = sin(xaxis);
% Determine the points with positive x coordinates and plot them
% Let's plot the negative x coordinates as well for illustration
hold on
Don on 4 Oct 2016
yay! this one worked. I accepted the earlier answers too quickly

Massimo Zanetti on 4 Oct 2016
Yes, because you are plotting just on point. Better try this:
plot(xaxis,yaxis)

Gareth Thomas on 4 Oct 2016
Edited: Gareth Thomas on 4 Oct 2016
You need to add the hold on command. Try this:
for i = 1:length(xaxis); hold on;if xaxis(i) >0; plot(xaxis(i),yaxis(i),'x'); end; end;
Notice the 'x' which helps you see it.

Gareth Thomas on 4 Oct 2016
for i = 1:length(xaxis); hold on ;if xaxis(i) >0; plot(xaxis(i),yaxis(i),'x'); end; end;