简体   繁体   中英

plot piecewise function in matlab

This is my code:

p=.2; 
x=-1:20; 
px=p*(1-p).^(x-1).*(x>=1); 
Fx=cumsum(px);
figure; 
subplot(2,1,1); 
stem(x,px);
subplot(2,1,2); 
stairs(x,Fx); 
hold on; 
stem(x,Fx,'w.')

I want to draw a circle mark at the right end of each horizontal line on the second subplot. Could someone show me how to do? Thanks in advance~

Things like following figure, but move the circle to the right end of each line. 在此处输入图片说明

You can use plot or scatter to draw the red circles.

Add one of the following instructions at the end of your script, they give the same output.

% Option 1: using plot
plot(x+1,Fx,'or');

% Option 2: using scatter
scatter(x+1,Fx,'r');

As you can see, my approach was to simply add 1 to every element of x . This is essentially shifting your data 1 unit in the x direction.

This is what you get:

向右散布圆圈

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM