why won't this plot?

4 vues (au cours des 30 derniers jours)
Don
Don le 4 Oct 2016
Commenté : Don le 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

Réponse acceptée

Steven Lord
Steven Lord le 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
positiveXAxisMask = xaxis > 0;
plot(xaxis(positiveXAxisMask ), yaxis(positiveXAxisMask ), 'x')
% Let's plot the negative x coordinates as well for illustration
hold on
plot(xaxis(~positiveXAxisMask ), yaxis(~positiveXAxisMask ), 'o')
  1 commentaire
Don
Don le 4 Oct 2016
yay! this one worked. I accepted the earlier answers too quickly

Connectez-vous pour commenter.

Plus de réponses (3)

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

Gareth Thomas
Gareth Thomas le 4 Oct 2016
Modifié(e) : Gareth Thomas le 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
Gareth Thomas le 4 Oct 2016
for i = 1:length(xaxis); hold on ;if xaxis(i) >0; plot(xaxis(i),yaxis(i),'x'); end; end;

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by