How to convert a continuous figure to discrete?

5 views (last 30 days)
The figure is exactly looks like below I provided. It's actually kind of a bit vector [1 1 1 1 1 1 1 0 1 1] so I expect from it that goes to 0 directly at 8, Not by linear way; by another meaning I want it looks like a square wave there.
I tried to use 'c2d' but couldn't get what I want.
Thanks in advance
fur.png

Accepted Answer

David K.
David K. on 22 Jul 2019
A couple different ways to do this. When plotting discrete values it is often preferred to use stem instead of plot. It does not connect the lines so probably not what you want. What you likely want is the answer from this question :
What they do is they add more samples so that the plot looks square.
They do it in a way that will work for any bit series :
x = [1 1 1 1 1 1 1 0 1 1];
x = repmat(x',1,100)';
x = x(:)';
t = linspace(0,10,numel(x));
plot(t,x)
Where the 100 is somewhat arbitrarily chosen as a higher order.
This is currently set up so that the plot becomes 0 and 7 and 1 at 8. Since I'm not sure that is exactly how you want it. When plotting you could probably do
plot(t+.5,x)

More Answers (0)

Community Treasure Hunt

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

Start Hunting!