More efficient xlsread for curve fitting
3 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
Mark Whirdy
2012-7-18
Hi Jonathan
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)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Web Services 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!