Matlab AND operation concerning intervals
Ältere Kommentare anzeigen
I am trying to create a simple signal with the following code:
function s = r_tri(t)
if ((t >= 0) & (t <= 3))
s = (-2/3)*t + 2;
else
s = 0;
end
Every time I try and plot this I get a blank graph. I assigned t = -1: 0.01: 4; I used the following plot command:
plot (t, r_tri(t))
I also tried this on the command line, and I keep getting 0. Why is this happening? Can you suggest a better way to accomplish this? Thanks.
Akzeptierte Antwort
Weitere Antworten (1)
Azzi Abdelmalek
am 2 Apr. 2016
t = -1: 0.01: 4;
s=zeros(size(t))
idx=t>=0 & t<=3;
s(idx)=(-2/3)*t(idx) + 2;
plot(t,s)
1 Kommentar
Aaron Friedman
am 3 Apr. 2016
Kategorien
Mehr zu Mathematics finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!