# Stairs plot with solid horizontal lines and dashed vertical lines in MATLAB [closed]

I want to create a stairs plot with solid horizontal lines and dashed vertical lines. You can see an example of what I am trying to do in this question (scroll down a little bit). In the example, however, they use Python, but I want to do this in MATLAB.

My (simple) code is

k=-4:1:4;
a= (2*k +1)/2;
t=-4:0.1:4;

figure()
stairs(k,a,'r')
hold on
plot(t,t)


My plot becomes

I have no idea what to do. Any help is appreciated!

• I think you'll have to draw individual line segments yourself if you really want this in MATLAB, unfortunately... – Memming Sep 11 '15 at 14:51
• There does not seem to be a computational task involved here, but rather a question about plotting with MATLAB. I would turn to the MATLAB Newgroup for advice in this particular case. – hardmath Sep 13 '15 at 20:26

As mentioned in the comments to your original post, with MATLAB you will have to draw the individual line segments. Try this:

k=-4:1:4;
a=(2*k +1)/2;
t=-4:0.1:4;
n = size(k,2);

figure(1)
[xb,yb] = stairs(k,a); % gives us the x and y coordinates
stairs(k,a,'r--'); % the plot
hold on
for i = 1:2:(2*n-2) % size(xb) == size(yb) = 2*n-1
% overplot black line segments
plot(xb(i:i+1),yb(i:i+1),'k')
end


The end result looks as follows: