How can I draw multiple functions base on same t (time) but different intervals?

I have one main function dependent on t, like:
t=-1:0.1:12;
x=@(t) [(t).*((t >= 0)&(t<=3)) + (3*ones).*((t>3)&(t<=4)) + (2*ones).*((t>4)&(t<5)) + (2*(6-t)).*((t>=5)&(t<=6))];
Then I created several functions from this function, like:
a=x(t-4);
b=x(t+1);
c=x(3*t);
d=x(t/2);
Now I want to plot these functions in the one same graph, but I want every function in different t intervals because I don't want to see the functions where that are 0. It causes visual pollution to me. For exp:
I try fplot function to get over this. I succeed draw main function that I want but when I want to draw the other functions the result like this:
I don't understand why this occurs. But at the end I am open to any help.
Thanks for the replies.

2 Comments

It works but reverse, like exp: I want (t-4) means shift to right but it shifts left when I do the way you tell. I can calculate and write the reverse, so it can do it correct but I don't want this.

Sign in to comment.

 Accepted Answer

I can finally find the solution. Here it is:
t=-1:0.01:12;
x= f(t)
a= f(t-4)
b= f(t+1)
range=(t>=0)&(t<=6);
a_range=(t>=4)&(t<=10);
b_range=(t>=-1)&(t<=5);
plot(t(range),x(range),'LineWidth',2);
hold on;
plot(t(a_range),a(a_range),'LineWidth',1);
plot(t(b_range),b(b_range),'LineWidth',1);
grid on;
function x = f(t)
x=[(t).*((t >= 0)&(t<=3)) + (3*ones).*((t>3)&(t<=4)) + (2*ones).*((t>4)&(t<5)) + (2*(6-t)).*((t>=5)&(t<=6))];
end

More Answers (0)

Products

Release

R2019b

Asked:

on 16 Mar 2021

Answered:

on 18 Mar 2021

Community Treasure Hunt

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

Start Hunting!