how to plot random ones and zeros as sequare wave?

i am trying to plot my random binary signal as square wave using these simple code
s=rand(1,10)>0.5;
t=1:1:10;
plot(t,s);
but its appear as triangle wave as shown below

 채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2013년 3월 9일
편집: Azzi Abdelmalek 2013년 3월 9일

2 개 추천

n=20
s=rand(1,n)>0.5;
s=repmat(s',1,100)'
s=s(:)'
t=linspace(0,n,numel(s))
plot(t,s,'r')

댓글 수: 1

Excuse me, could you help me to generate triangle signal starts from 0 to 60 degree and stops and then starts from 120 to 180 and then repeat itself, either by coding or simulink, please?

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

추가 답변 (1개)

Wayne King
Wayne King 2013년 3월 9일

0 개 추천

It is better to use stem() for this purpose
s=rand(1,10)>0.5;
t=1:1:10;
stem(t,s,'markerfacecolor',[0 0 1])

카테고리

도움말 센터File Exchange에서 Audio I/O and Waveform Generation에 대해 자세히 알아보기

태그

질문:

2013년 3월 9일

댓글:

2019년 8월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by