How to make a graph of a three-branches function in matlab
问题 How can I make this function's graph in Matlab, so that its body is depicted in the same graph (plot or subplot)? t0=0.15 x(t)= 1, if 0<=t<(t0/2) -2, if (t0/2)<=t<=(3/2)*t0 0, else 回答1: The real question you should be asking is "How to define a function that has branches?", since plotting is easy once the function is defined. Here's a way using anonymous functions: x_t = @(t,t0)1*(0<=t & t<t0/2)-2*(t0/2<=t & t<=(3/2)*t0); %// the 1* is redundant, I only %// left it there for clarity Note that