使用/ Matrix尺寸时出错必须同意

时间:2014-02-27 01:47:36

标签: matlab matrix

我正在尝试使用匿名函数为我的数据创建洛伦兹分布。高斯分布创建没有问题,但洛伦兹分布遇到此错误。

错误:

  

使用/

时出错      

矩阵尺寸必须达成一致。

     

@(p,x)1 /(pi * p(2)*(1 +((x-p(1))/(p(2)))中的错误。^ 2))

代码:

% Variables necessary for histograms
num_bins = 100;
low_range = linspace(min(low_data), max(low_data), num_bins);
low_counts = histc(low_data, low_range);
low_err = sqrt(low_counts);  


% Creating and testing fits
gauss_fun_form = @(p, x) 1/(p(2)*sqrt(2*pi))*exp(-(x-p(1)).^2/(2*p(2).^2));
loren_fun_form = @(p, x) 1/(pi*p(2)*(1+((x-p(1))/(p(2))).^2));

low_avg = mean(low_data);
low_std = std(low_data);    

low_gauss_param = [low_avg low_std];
low_gauss = gauss_fun_form(low_gauss_param, low_range);
low_gauss_scale = max(low_counts)/max(low_gauss);

low_loren_param = [low_avg 2*log(2)*low_std];
low_loren = loren_fun_form(low_loren_param, low_range);
low_loren_scale = max(low_counts)/max(low_loren);

1 个答案:

答案 0 :(得分:1)

(pi*p(2)*(1+((x-p(1))/(p(2))).^2)) generate vector of 100 dimensions

虽然1是1维向量,但矩阵除法无效,应该应用./。更改loren_fun_form的定义如下所示

loren_fun_form = @(p, x) 1./(pi*p(2)*(1+((x-p(1))/(p(2))).^2));