How to convert a continuous figure to discrete?

5 vues (au cours des 30 derniers jours)
Enez Furkan Cihan
Enez Furkan Cihan le 22 Juil 2019
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

Réponse acceptée

David K.
David K. le 22 Juil 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)
  1 commentaire
Enez Furkan Cihan
Enez Furkan Cihan le 22 Juil 2019
I appreciate, David! It really helped out.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by