Why can't I plot a simple line???

2 views (last 30 days)
daniel
daniel on 8 Dec 2014
Commented: daniel on 8 Dec 2014
I am trying to change the limits of my axis, and just draw a line through x = 0. But for some reason if I only specify a solid line in my LineStyle, matlab wont plot anything, if I choose anything else it works fine i.e *,o,>,<.... I will just do a simple example to illustrate my point.
>> figure
>> hold on
>> grid on
>> set(gca,'LineWidth',1)
>> axis([-10,10,0,30]);
>> plot(0,0:1:30,'r-') %% this produces nothing
>> plot(0,0:1:30,'r-*')%% this and everything else does..
>> plot(0,0:1:30,'r-o')
>> plot(0,0:1:30,'r->')
>> plot(0,0:1:30,'r-<')
Any idea why? Any help will be appreciated.
-D

Accepted Answer

Mohammad Abouali
Mohammad Abouali on 8 Dec 2014
Well, if you change
plot(0,0:1:30,'r-')
to
plot(zeros(1,31),0:1:30,'r-')
it would generate a line.
However, if you want to change your axis limit that is not a proper approach
Use
xlim([minXAxisValue maxXAsixValue])
ylim([minYAxisValue maxYAsixValue])
  3 Comments
daniel
daniel on 8 Dec 2014
Mohammad, suppose I want to plot a line across y = -15.
plot(0:1:100,-15.*ones(101,1),'r-')
will produce the line but is there a cleaner way of doing this?

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!