fitting a function to data by changing a variable

조회 수: 1 (최근 30일)
Robert Roy
Robert Roy 2018년 8월 21일
댓글: Saumya Goel 2018년 8월 30일
stem='I:\Engineering\ChemEng\LaserGroup\Robert\Data\PMT HAB Measurements\21st Sept PMT HAB Profile\HAB Measurements\Eq1.7HAB';
n=18
r=n-1;
r_Profile(n)=r;
r=int2str(r);
rest='.csv';
combinedStr=strcat(stem,r,rest);
Profile=csvread(combinedStr,50010,0,[50010,0,51000,1]);
t=Profile(:,1);
sig=Profile(:,2);
sig=sig-mean(sig(1:100));
sig=-((sig));
max_Profile(n)=max(sig).';
figure;
plot(t,sig);
nlinfit(t,sig,myfun)
Hi there, I would like to fit the data read in by 'stem' to myfun which is a modelled function in a different script which changes the variable named dp? Thanks
  댓글 수: 1
dpb
dpb 2018년 8월 21일
"... myfun which is a modelled function in a different script "
Have to save myfun as an m-file; functions in scripts are local within the script and thus aren't visible outside the script.

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

채택된 답변

Saumya Goel
Saumya Goel 2018년 8월 30일
If the function you are referring (myfun) is defined in a script, then it is going to be a local function and cannot be accessed outside the script. In that case, as dpb pointed out you may have to save myfun as an m-file and add it to the MATLAB path.
Also, make sure you are passing the argument as function handle in nlintfit function. Please find the documentation for the nlintfit function.
If you would like to know more about the function handle, you can find here.
  댓글 수: 2
Robert Roy
Robert Roy 2018년 8월 30일
Thanks, Im now able to read in the function from another script now. Now I just have a problem with the nlinfit saying that theres not enough input variables?
Saumya Goel
Saumya Goel 2018년 8월 30일
I believe this MATLAB answer might help you resolve the above issue.

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by