Well, my colleague helped me to modify this and now it works perfectly. I hope this solution helps anyone:
Changes to make in the code above:
- Use just one loop for ii=1:numel(S_names) ... end (no need to involve two loops).
- Get all the 3 parameters separately by using table2array and specifying a given column in D (this is to extract a given column from the excel file).
- If any variable is imported as a cell, which might be an issue, use str2double, for example that way:
if iscell(parameter)
parameter = str2double(parameter);
end
No need for transposing anything now.
- Then continue with deleting the 2nd for loop and deleting the indexing with curly braces and brackets as follows.
Q = @(A) sum ((perm - A(1).*(t2lm.^A(2)).*por.^A(3)).^2);
a = fminsearchbnd(Q, [50,4,6], [0,0,0]);
p{ii, :}=a(1).*(t2lm'.^a(2)).*por'.^a(3);
Note that the indexing is only needed for "p" to let the code generate the complete list of the "perm" parameter, for which we solve.
You may also want to see the whole list of the a1-a2-a3 coefficient before they become overwritten in the loop. Simply use something like:
mycoeffs(ii,:) = a;
Best regards,
Ace.