Error: Assignment has more non-singleton rhs dimensions than non-singleton subscripts

I want to fit the following model to a set of data. The input data is P. A 5x243 Matrix. The output data is B. A 3x243 Matrix. MatLab is giving me the following Error:
>> [estimates, model] = fitcurvedemo(P, B)
Assignment has more non-singleton rhs dimensions than non-singleton subscripts
Error in fminsearch (line 189)
fv(:,1) = funfcn(x,varargin{:});
Error in fitcurvedemo (line 4)
estimates = fminsearch(model, start_point);
I have absolutely no idea why something is wrong with the dimensions. I have checked them several times but can't find a mistake. I have the feeling it could be because of the parameters. It would be great, if someone could help me! Thanks in advance! Below is my code:
function [estimates, model] = fitcurvedemo(P, B)
start_point = rand(5, 1);
model = @model3n;
estimates = fminsearch(model, start_point);
function [sse, FittedB] = model3n(params)
rho = params(1);
a = params(2);
b = params(3);
c = params(4);
d = params(5);
V = a.*sqrt(2/rho.*abs(P));
for k = 1:243
if P(1,k)>=0
Z(1,k) = -V(1,k);
else Z(1,k) = V(1,k);
end
end
for k = 1:243
if P(2,k)>=0
Z(2,k) = -V(2,k);
else Z(2,k) = V(2,k);
end
end
for k = 1:243
if P(3,k)>=0
Z(3,k) = V(3,k);
else Z(3,k) = -V(3,k);
end
end
for k = 1:243
if P(4,k)>=0
Z(4,k) = -V(4,k);
else Z(4,k) = V(4,k);
end
end
for k = 1:243
if P(5,k)>=0
Z(5,k) = V(5,k);
else Z(5,k) = -V(5,k);
end
end
alpha = b.*Z(1,:);
betha =c.*(Z(2,:)-Z(3,:));
velocity =d.*(Z(4,:)-Z(5,:));
FittedB = [alpha;betha;velocity];
ErrorVector = FittedB - B;
sse = sum(ErrorVector .^ 2);
end
end

답변 (0개)

카테고리

도움말 센터File Exchange에서 Mathematics에 대해 자세히 알아보기

태그

질문:

2016년 9월 28일

댓글:

2016년 9월 29일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by