Hi, I am a not an advanced user of matlab, and was wondering if there was a more efficient way to run a model of mine.
The model takes a set of data (pair distribution function) and fit a given crystal structure to the set. I use either lsqcurvefit or nonlinfit for this. Below is the main 2 lines of code. I fit my data and then rerun with the optimized fit.
A7lsq = lsqcurvefit( @gA7loop, x0, x, y(:,i), lb, ub, options); g_r = gA7loop(A7lsq, x);
The first line in my inside function gA7loop is an xlsread function to read the nearest neighbor distance and # of nearest neighbors for a given crystal structure.
function g_r = gA7loop(x,R) ri_a = xlsread('nn80to85.xlsx','B2:B352');
Is there a more efficient way to use the xlsread function so that it can be read once prior to the curve fit, and not read however many iterations the curve fit goes through the data? All the classes I have had in programming always say to stay away from global variables, but I am wondering is this a good place to use them?
If more code is required to understand my question/problem I can add the full files. Thank you in advance for any help in the matter
No products are associated with this question.
Subfunctions have caller-scope (can see variables which are set in the functions that call them). So put the xlread in the caller function.
Also, a better solution to xlsread generally, the use the acxtserver methods (in the link below I provided some sample code which can be adapted)