Error: Function value and YDATA sizes are not equal

I have a fitting code with lsqcurvefit function. I am having this error "Function value and YDATA sizes are not equal"(line 251). Please give your suggestion to solve it.
clear all, close all, clc
EQE = xlsread('EQERollOff','Sheet1','A30:B55');% loading raw data from excel file
x = EQE(:,1);% Current
y = EQE(:,2);% EQE
%parameter estimation
J0 = [6];
options = optimset('Algorithm', 'trust-region-reflective');
[J,Rsdnrm,Rsd,ExFlg,OptmInfo,Lmda,Jmat] = lsqcurvefit(@EQEFit,J0,x,y)
function s = EQEFit(J,x)% function for fitting
s = J(1)/(4*x)*(sqrt(1+8*(x/J(1)))-1)*5
end
Size of x = 26 1, Size of y = 26 1

 Accepted Answer

As a bold guess I'm going to assume you meant this:
function s = EQEFit(J,x)% function for fitting
s = J(1)./(4*x).*(sqrt(1+8*(x/J(1)))-1)*5;
end
(I don't have the Optimization Toolbox, so I can't test the code)

3 Comments

Hi Rik, it worked. Thanks for your help. Just wondering as J(1) is scalar then why J(1)./(4*x) did work? I am new in in coding. Please explain so I can avoid doing the same mistake again. Cheers
There are two operations here that are potentially matrix operations: the division and multiplication. Since the multiplication returns a vector, this would be equivalent to finding an inverse for that vector and then multiplying that with J(1).
so this:
J(1)/(4*x)
is parsed like this:
J(1) * 1/(4*x)
The most important thing is to be aware that these operators have two imputs: the prior term and the second term.
The more practical thing is to watch out with these, and adding a dot when in doubt:
*/^'

Sign in to comment.

More Answers (0)

Categories

Products

Release

R2017b

Asked:

on 22 Jan 2019

Commented:

on 29 Jan 2019

Community Treasure Hunt

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

Start Hunting!