Dataset to Square Wave

1 vue (au cours des 30 derniers jours)
Martin Androvich
Martin Androvich le 30 Avr 2018
I have an array of datapoints; y being a boolean and x being some distance at which that boolean is changed.
I can plot it just fine, but I was wondering if there was an simple and quick way of converting the "usual" linear plot such that the data is represented with rising and falling edges, like a square wave, as pictured below:
I can do this manually, but there might be a neat way of doing so that I don´t know of.

Réponse acceptée

Fangjun Jiang
Fangjun Jiang le 1 Mai 2018
a little awkward, but should serve you well
x=[0 32 37 45 53]';
y=[0 1 0 1 0]';
a=x([2:end,end]);
a=reshape([x,a]',[],1);
b=reshape([y,y]',[],1);
plot(a,b,'r*-')
  1 commentaire
Martin Androvich
Martin Androvich le 4 Mai 2018
Brilliant, thank you!

Connectez-vous pour commenter.

Plus de réponses (0)

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by