How to use a matrix of variables with fminsearch?
4 views (last 30 days)
Show older comments
Erick Alejandro
on 1 Mar 2014
Answered: Walter Roberson
on 1 Mar 2014
Hi,
I am trying to fit four experimental curves simultaneously. Each of the four curves is generated from six parameters. The input matrix needs to be a 6x4 matrix, six parameters per column for each of the curves. So when I call fminsearch:
[bestvars, chisquared] = fminsearch(@minimize, parametermatrix, options, ...)
Where ... are other matrices or vectors I need to input for later parts of the program.
It gives the error:
Subscripted assignment dimension mismatch.
Error in fminsearch (line 191) fv(:,1) = funfcn(x,varargin{:});
Error in entropification (line 27) [bestvars, chisquared] = fminsearch(@minimize, parametermatrix, options, ...);
If I use just a vector from parametermatrix, and use these variables for all four curves, instead of six unique parameters for each curve, it works. However, this doesn't give me the unique bestvars for each curve.
My minimization function is a chisquared function. The numbers and 10e-6 in there are just for unit conversions so ignore those:
[mutCpcal, mutCp_folded, mutCp_unfolded] = gencps(parametermatrix, mutt); for i = 1:length(mutt) for j = 1:size(mutt,2) mutCperror(i,j) = ((((mutPstd(i,j).*10^-6.*60)./(conc.*0.0003268))./sqrt(mutN(j,1))))./1000; mutsumchisq(i,j) = (((mutcp(i,j) - mutCpcal(i,j)))./(mutCperror(i,j))).^2; end end chisq = sum(sum(mutsumchisq));
And this returns the scalar value from doubly summing mutsumchisq so it should output the correct format.
With a matrix of variables as the fminsearch input, the program will only go through one iteration before giving me the fminsearch error. It seems that MatLab is not liking having a matrix of variables as the input for varying. Any help is greatly appreciated.
0 Comments
Accepted Answer
Walter Roberson
on 1 Mar 2014
Use a vector of 24 parameters. reshape() the vector inside the function so you can get at the rows or columns.
0 Comments
More Answers (0)
See Also
Categories
Find more on Interpolation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!