Echo0831
Echo0831

Reputation: 307

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. enter image description here

Upvotes: 0

Views: 409

Answers (1)

codeaviator
codeaviator

Reputation: 2575

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:

Scatter circles to the right

Upvotes: 1

Related Questions