求解释: MATLAB Error using ==> plot Vectors must be the same lengths.set(0,'defaultaxeslinestyleorder',{'-*','-o',':s','-.d'});set(gca,'Xtick',[-10 10 130],'Xticklabel',{'-10','10

来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/24 23:55:00
求解释:MATLABErrorusing==>plotVectorsmustbethesamelengths.set(0,'defaultaxeslinestyleorder',{&#

求解释: MATLAB Error using ==> plot Vectors must be the same lengths.set(0,'defaultaxeslinestyleorder',{'-*','-o',':s','-.d'});set(gca,'Xtick',[-10 10 130],'Xticklabel',{'-10','10
求解释: MATLAB Error using ==> plot Vectors must be the same lengths.

set(0,'defaultaxeslinestyleorder',{'-*','-o',':s','-.d'});

set(gca,'Xtick',[-10 10 130],'Xticklabel',{'-10','10','130'});

n1=300;

q=1;

b=10^(-4)/q;

E3=25/(q/b)^0.5;

A=100;

N=n1*A;

d=4;

i=0;

if d>0.5

 for d=4:-0.1:0.5

    i=i+1;

    f=@(z)(z-d).^(3/2).*1/sqrt(2*pi).*exp(-z.^2/2);

    Q(i)=quad(f,d,40);

    P1(i)=Q(i)*4/3*N*E3*sqrt(b);

    plot(P1,4:-0.1:0.5,'g')

 end

end

hold on

 if d<=0.5

    for d=0.4:-0.1:0

    i=i+1;

    f=@(z)(z-d).^(3/2).*1/sqrt(2*pi).*exp(-z.^2/2)+3;

    Q(i)=quad(f,d,40);

    P2(i)=Q(i)*4/3*N*E3*sqrt(b); 

    plot(P2,0.4:-0.1:0,'g')

    end

 end


相当于分段函数


结果如下,为什么? 


求解释: MATLAB Error using ==> plot Vectors must be the same lengths.set(0,'defaultaxeslinestyleorder',{'-*','-o',':s','-.d'});set(gca,'Xtick',[-10 10 130],'Xticklabel',{'-10','10
把plot从for循环里面拿出来,放到循环的后面,你现在每次for循环都会做一次plot,但在你的for循环结束之前,你的P1和P2根本都还没全部赋值完毕