How to make a graph of a three-branches function in matlab

后端 未结 2 357
名媛妹妹
名媛妹妹 2021-01-16 04:35

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<(         


        
2条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-16 05:30

    I'm not sure of what you want, but would it be it?

    clc
    close all
    clear
    
    t0 = 0.15;
    
    t = 0:0.01:0.15;
    
    x = zeros(size(t));
    
    x(0 <= t & t < (t0/2)) = 1;
    x((t0/2) <= t & t <= (3/2)*t0) = -2;
    
    figure, plot(t, x, 'rd')
    

    which gives,

    enter image description here

    Everything depends on the final t, for example if the end t is 0.3, then you'll get,

    enter image description here

提交回复
热议问题