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
Steven Lord 2016년 10월 4일

3 개 추천

% 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

Don
Don 2016년 10월 4일
yay! this one worked. I accepted the earlier answers too quickly

댓글을 달려면 로그인하십시오.

추가 답변 (3개)

Massimo Zanetti
Massimo Zanetti 2016년 10월 4일

3 개 추천

Yes, because you are plotting just on point. Better try this:
plot(xaxis,yaxis)
Gareth Thomas
Gareth Thomas 2016년 10월 4일
편집: Gareth Thomas 2016년 10월 4일

0 개 추천

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 2016년 10월 4일

0 개 추천

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

카테고리

도움말 센터File Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

질문:

Don
2016년 10월 4일

댓글:

Don
2016년 10월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by