Dataset to Square Wave

조회 수: 1 (최근 30일)
Martin Androvich
Martin Androvich 2018년 4월 30일
댓글: Martin Androvich 2018년 5월 4일
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.

채택된 답변

Fangjun Jiang
Fangjun Jiang 2018년 5월 1일
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
Martin Androvich
Martin Androvich 2018년 5월 4일
Brilliant, thank you!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by