How do I fix this error: "Error using minus Matrix dimensions must agree"?
조회 수: 1 (최근 30일)
이전 댓글 표시
Here is my script:
function f = objectiveL2(p, pIndex, data, trainingIndex, kinesinName, lambda)
if length(p) ~= size(pIndex,1)
error('p and pIndex must have the same length');
end
p00 = InitialParameterValues(kinesinName);
p0 = InitialParameterValues(kinesinName);
for i = 1:size(pIndex,1)
for j = 1:size(pIndex,2)
if pIndex(i,j) ~= 0
p00(pIndex(i,j)) = p(i)*p00(pIndex(i,j));
end
end
end
for i = 1:size(data,1)
if strcmp(data(i,1).kinesinName,kinesinName)
kinesinIndex = i;
break;
end
end
f = 0;
for i = 1:length(trainingIndex)
% Define initial conditions for the model
x0 = zeros(12,1);
x0(1) = data(kinesinIndex,trainingIndex(i)).kinesinConc; % Kinesin
x0(2) = data(kinesinIndex,trainingIndex(i)).MTConc; % MT
x0(8) = data(kinesinIndex,trainingIndex(i)).mantATPConc; % mantATP
tspan = [0;data(kinesinIndex,trainingIndex(i)).time];
[~,x] = ode45(@(t,x,p) SteppingModel_no78(1,x,p00), tspan, x0);
y_model = p00(15)*(x(2:end,9)+x(2:end,10));
y_data = data(kinesinIndex,trainingIndex(i)).fluorescence - 1;
f = f + sum((y_model - y_data).^2)/length(y_data);
end
f = f + lambda*sum(((p0(1:14) - p00(1:14))./p0(1:14)).^2);
end
Here is the error I get
Error using -
Matrix dimensions must agree.
Error in objectiveL2 (line 38)
f = f + sum((y_model - y_data).^2)/length(y_data);
Error in @(p)objectiveL2(p,pIndex,data,trainingIndex,kinesinName,0.0000000000001)
Error in fmincon (line 534)
initVals.f = feval(funfcn{3},X,varargin{:});
Error in main (line 60)
[pFit, fval, flag] = fmincon(@(p) objectiveL2(p, pIndex, data, trainingIndex, kinesinName, 0.0000000000001), ...
Caused by:
Failure in initial user-supplied objective function evaluation. FMINCON cannot continue.
I know where the error is occurring (line 38), but I really don't know how to fix it. It looks correct to me. Any help would be greatly appreciated.
Thanks!
댓글 수: 2
Geoff Hayes
2016년 1월 28일
Sean - what are the dimensions of y_model and y_data? Since you are subtracting one from the other, they must have the same number of rows and the same number of columns.
Walter Roberson
2016년 1월 29일
Where is kinesinIndex being defined? Is it a function, or is it being defined in an outer function that this one is nested inside?
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Particle & Nuclear Physics에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!