是统计轨迹,并画一定范围之内数据的高斯分布。
真TMD优雅,我靠。
- clear all
- clc
- clf
- dat=load('../data/combine.dat');
- n=length(dat(:,1));
- x=(1:n)/10;
- dat1=dat(500:end,1);
- dat2=dat(500:end,2);
- bi = linspace(-13,-6,70);
- [hi1,bi1]=hist(dat1,bi);
- [hi2,bi2]=hist(dat2,bi);
- fx=@(b,x)b(1)/sqrt(2*pi*b(2))*exp(-(x-b(3)).^2/(2*b(2)^2));
- x_bin=bi;
- x1=linspace(min(x_bin),max(x_bin),200);
- y1 = hi1;
- b0=[35,2,-8];
- b=b0;
- for l=1:10
- % Solve nonlinear curve-fitting problems in least-squares sense.
- % just a guess.
- b=lsqcurvefit(fx,b,x_bin,y1);
- % Nonlinear regression,
- b=nlinfit(x_bin,y1,fx,b);
-
- end
- b1=b;
- y_hi1 = fx(b1,x1);
- y2 = hi2;
- b0=[30,2,-11];
- b=b0;
- for l=1:10
- % Solve nonlinear curve-fitting problems in least-squares sense.
- % just a guess.
- b=lsqcurvefit(fx,b,x_bin,y2);
- % Nonlinear regression,
- b=nlinfit(x_bin,y2,fx,b);
-
- end
- b2=b;
- y_hi2 = fx(b2,x1);
-
- % hold on
- % plot(bi1,hi1,'r.')
- % plot(x1,y_hi1,'r-')
- %
- % plot(bi,hi2,'b.')
- % plot(x1,y_hi2,'b-')
- mm_font=14;
- h=figure(1);
- set(h, 'Position', [100, 100, 800, 400]);
- % subplot(1,2,1)
- pos1=[0.1 0.1 0.6 0.8];
- subplot('position',pos1)
- hold on
- x_pat1=[ 50 100 100 50];
- y_pat1=[-13.1 -13.1 -5.9 -5.9];
- h_pat1=patch(x_pat1,y_pat1,'gray')
- alpha(h_pat1,0.1);
- plot(x,dat(:,1),'r-')
- plot(x,dat(:,2),'b-')
- axis tight
- box on
- axis ([0 100 -13.1 -5.9])
- set(gca,'fontsize',mm_font);
- set(gca,'xtick',[0:10:100]);
- % subplot(1,2,2)
- pos2=[0.7 0.1 0.2 0.8];
- subplot('position',pos2)
- hold on
- x_pat2=[ 0 50 50 0];
- y_pat2=[-13.1 -13.1 -5.9 -5.9];
- h_pat2=patch(x_pat2,y_pat2,'gray')
- alpha(h_pat2,0.1);
- plot(y_hi1,x1,'r-','linewidth',2)
- plot(y_hi2,x1,'b-','linewidth',2)
- hi = [hi1;hi2]';
- h_bar=barh(bi,hi);
- h1=h_bar(1);
- h2=h_bar(2);
- set(h1,'facecolor','r','edgecolor','none','barwidth',2.5)
- set(h2,'facecolor','b','edgecolor','none','barwidth',2.5)
- axis([0 50 -13.1 -5.9])
- set(gca,'ytick',[]);
- text(20,-6.5,['\mu=',mat2str(floor(b1(3)*1000)/1000)],'fontsize',mm_font)
- text(20,-7.0,['\sigma=',mat2str(floor(b1(2)*1000)/1000)],'fontsize',mm_font)
- text(20,-12,['\mu=',mat2str(floor(b2(3)*1000)/1000)],'fontsize',mm_font)
- text(20,-12.5,['\sigma=',mat2str(floor(b2(2)*1000)/1000)],'fontsize',mm_font)
- set(gca,'fontsize',mm_font);
- box on
- h=gcf;
- fi_na=['../file_img/fig_traj_hist'];
- fun_work_li_035_myfig_out(h,fi_na,3);
- % plot(dat(:,1),dat(:,2),'.')
复制代码
|