필터 지우기
필터 지우기

More efficient xlsread for curve fitting

조회 수: 1 (최근 30일)
Jonathan
Jonathan 2012년 7월 18일
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

답변 (1개)

Mark Whirdy
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)
  댓글 수: 2
Jonathan
Jonathan 2012년 7월 22일
Hi Mark, the link provided is a link to this page. If you could repost the original link, that would be much appreciated. Thanks
Mark Whirdy
Mark Whirdy 2012년 11월 13일
Apologies Jonathan - I guess you've solved this since but ...

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Interpolation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by