Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab 绘制函数时出错_Matlab_Function - Fatal编程技术网

Matlab 绘制函数时出错

Matlab 绘制函数时出错,matlab,function,Matlab,Function,我试图建立并绘制一个振幅为1的三角形函数,从第二个1开始,在第二个3达到最大值,在第二个4回到零 x(A,t1,t2,t3,t)=A/t2-t1*(t-t1),当t1这里有一个示例,给定波形的百分比/占空比和周期t,手动创建三角形波形的上升和下降部分 T = 3; % period in secs rise_pct = 2/3; % percentage of wave rising fall_pct = 1/3; % percentage of wa

我试图建立并绘制一个振幅为1的三角形函数,从第二个1开始,在第二个3达到最大值,在第二个4回到零


  • x(A,t1,t2,t3,t)=A/t2-t1*(t-t1)
    ,当
    t1这里有一个示例,给定波形的百分比/占空比和周期t,手动创建三角形波形的上升和下降部分

    T = 3;              % period in secs
    rise_pct = 2/3;     % percentage of wave rising
    fall_pct = 1/3;     % percentage of wave falling
    dt = 0.01;          % time interval
    
    N_repeats = 2;
    
    rise = linspace(0,1,T*rise_time/dt);    % create rising section
    fall = linspace(1,0,T*fall_time/dt);    % create fallingsection
    wave = [rise,fall];                     % join rise and fall strokes
    
    wave = repmat(wave,1,N_repeats); %repeat wave
    
    t = (1:length(wave)).*dt + 1; %time vec starting at 1sec
    plot(t,wave);
    

    提示:在命令行上,检查
    t之间的差异我尝试了,并给出了不同的答案,但这并不能解决同一函数具有不同条件的问题。最简单的方法:预先分配长度
    t
    的空零向量,然后为两个条件中的每一个填入正确的值。谢谢,但这不仅仅是关于“三角形”,而是关于创建具有特定振幅和时间间隔的特定函数。。
    fs = 20;       %freq
    t = 0:1/fs:5;
    t1=1;
    t2=3;
    t3=4;
    A=1;           %amplitude
    
    x2 = mytri(A, t1, t2, t3, t);
    plot (t,x2,'.-')
    axis([ -2 5 -2 5])
    
    function x2 = mytri(A, t1, t2, t3, t)
        x2 = A/t2 - t1*t - t1*(t1 <= t <= t2);
    
    T = 3;              % period in secs
    rise_pct = 2/3;     % percentage of wave rising
    fall_pct = 1/3;     % percentage of wave falling
    dt = 0.01;          % time interval
    
    N_repeats = 2;
    
    rise = linspace(0,1,T*rise_time/dt);    % create rising section
    fall = linspace(1,0,T*fall_time/dt);    % create fallingsection
    wave = [rise,fall];                     % join rise and fall strokes
    
    wave = repmat(wave,1,N_repeats); %repeat wave
    
    t = (1:length(wave)).*dt + 1; %time vec starting at 1sec
    plot(t,wave);