I'm getting an error saying error using lsqcurvefit: function value and YDATA sizes are not equal. (line 11)
I've checked the number of elements in TR and S and it says they are equal, I have no idea what I'm doing wrong.
Can anyone help?
nativeP = load ('npcaa_t1w.mat');
funT1 = @(x, t) x(1).*(1 - exp(-t./x(2)));
x0 = [50, 1000];
lb = [0, 0];
ub = [500, 10000];
TR = nativeP.dataset.methodparx.MultiRepTime;
S = squeeze(nativeP.dataset.data(128, 128, :));
[x, resnorm, residual, exitflag, output] = lsqcurvefit(funT1, x0, TR, S, lb, ub);
S0 = x(1);
T1 = x(2);
Sfit = funT1(x, TR);
figure(5)
plot(TR, S, 'o')
hold on
plot(TR, Sfit)
xlabel('TR [ms]')
ylabel('S [A.U.] ')
title('Curve-fitting with lsqcurvefit')
legend('Measurement', 'Fitted Model')

댓글 수: 5

Torsten
Torsten 2023년 2월 12일
편집: Torsten 2023년 2월 12일
So if you insert the lines
size(TR)
size(S)
after the lines
TR = nativeP.dataset.methodparx.MultiRepTime;
S = squeeze(nativeP.dataset.data(128, 128, :));
in your code, you get really identical results ? Not transposed ? Not an additional dimension 1 ?
Then you must transpose one of the data arrays, e.g.
[x, resnorm, residual, exitflag, output] = lsqcurvefit(funT1, x0, TR, S.', lb, ub);
Donal Walsh
Donal Walsh 2023년 2월 12일
ans =
1 6
ans =
6 1
I don't understand why they are transposed?
How can i reverse this
Torsten
Torsten 2023년 2월 12일
I showed you in the modified call to the integrator above.
Donal Walsh
Donal Walsh 2023년 2월 12일
Sorted it thank you for pointing this out to me!

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

태그

질문:

2023년 2월 12일

댓글:

2023년 2월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by