![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/173692/image.png)
how to plot m(t)=cos(2*pi*9*t) 0<t<3 and m(t)=0 otherwise
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
sameh mostafa
am 15 Mär. 2016
Beantwortet: Juhi Maraskole
am 18 Aug. 2020
how to plot m(t)=cos(2*pi*9*t) 0<t<3 and m(t)=0 otherwise
0 Kommentare
Akzeptierte Antwort
Star Strider
am 15 Mär. 2016
This works:
m = @(t) cos(2*pi*9*t) .* ((t > 0 ) & (t < 3));
t = linspace(-1, 4, 500);
Out = m(t);
figure(1)
plot(t, Out)
grid
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/173692/image.png)
2 Kommentare
Star Strider
am 15 Mär. 2016
Change the ‘t’ assignment to:
t = linspace(-1, 4, 5000);
to improve the resolution by a factor of 10. Increase the third argument (here 5000) to get the resolution you want, if this is not enough.
Weitere Antworten (3)
Ced
am 15 Mär. 2016
Bearbeitet: Ced
am 15 Mär. 2016
You can use logical vectors to select certain parts of a vector.
t = -1:0.01:4;
m = zeros(length(t),1);
ind_interest = (t > 0 & t < 3); % this creates a logical vector
m(ind_interest) = cos(2*pi*9*t(ind_interest));
plot(t,m);
xlabel('time [s]')
Cheers
0 Kommentare
Siehe auch
Kategorien
Mehr zu Fourier Analysis and Filtering finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!