Input conditional sine wave

1 visualizzazione (ultimi 30 giorni)
Cameron Aldred
Cameron Aldred il 24 Apr 2017
Risposto: KSSV il 25 Apr 2017
Hi, I am trying to input a signal which is a sine wave between 3 and 7 seconds and zero everywhere else. I am trying to create an 'for loop' to do this by indexing the time vector but I can't make it work, the graph just displays nothing (assuming matlab thinks x = 0 for all time?)...is there anything I've missed?
t = [0:0.1:10];
for k=1:length(t)
if t(k)>=3 && t(k)<=7
x = 5*sin(4*pi *t);
else
x = 0;
end
end
plot(t,x)
Any help would be greatly appreciated :)

Risposta accettata

KSSV
KSSV il 25 Apr 2017
t = 0:0.1:10;
x = 5*sin(4*pi *t);
x(t<3) = 0 ;
x(t>7) = 0 ;
plot(t,x)

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by