필터 지우기
필터 지우기

Ploting a graph with if else statement

조회 수: 1 (최근 30일)
Ron
Ron 2018년 9월 30일
댓글: jonas 2018년 9월 30일
I am trying to plot this graph
fs=100000000 % samples per second
dt = 1/fs % seconds per sample
StopTime = 5E-6 % seconds
Fc = 5E6; % hertz
for t = (0:dt:StopTime) % seconds
if t<1E-6
y = 2*sin(2*pi*Fc*t)
else
y=0
end
end
plot (t,y) % Plot the signal versus time
The output of y is exactly what I need but I am unable to plot the graph of the y output with respect to time.
Thank you,

채택된 답변

jonas
jonas 2018년 9월 30일
편집: jonas 2018년 9월 30일

Try this instead, no for loop needed

fs = 100000000                
dt = 1/fs                  
StopTime = 5E-6             
Fc = 5E6;                   
t = 0:dt:StopTime
y = nan(size(t))
y(t<1E-6) = 2*sin(2*pi*Fc*t(t<1E-6))
y(~(t<1E-6)) = 0
plot(t,y)              
  댓글 수: 2
Ron
Ron 2018년 9월 30일
Thank You this works!!
jonas
jonas 2018년 9월 30일
Happy to help! Don't forget to accept the answer please!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graph and Network Algorithms에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by