How to make a discrete x-y plot with quiver instead of stem

1 view (last 30 days)
Hi,
I'm a matlab newbie. I made a simple X-Y plot with the stem command:
x=linspace(-10,10); x= -10:1:10; a= [0,0,0,0,0,0,0,0,0.5,0,0,0,0.5,0,0,0,0,0,0,0,0];
stem(x,a);
grid on;
But I'd like to get rid of the "circles" (points with y=0) and also add arrows to the vertical lines at x=-1 and x=+1).
I tried to use the quiver command without success. Can someone post some sample code using quiver (or stem if quiver can't do this)?
Thank you.

Accepted Answer

A Jenkins
A Jenkins on 13 Sep 2013
Edited: A Jenkins on 13 Sep 2013
Using quiver() as requested:
x= -10:1:10;
a= [0,0,0,0,0,0,0,0,0.5,0,0,0,0.5,0,0,0,0,0,0,0,0];
y=zeros(size(x));
v=zeros(size(x));
% yaxis matches but "ugly" arrowhead
figure(1)
quiver(x,y,v,a,0)
% yxis does not match but better arrowhead
figure(2)
quiver(x,y,v,a,2)
Compare figure(1) and figure(2). If you care about the arrowhead size versus y-axis scaling, you may want to check out the file exchange for a solution:

More Answers (0)

Categories

Find more on Vector Fields in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!