Convert (x,y) data into a function y => f(x)

조회 수: 47 (최근 30일)
Jaap de Vries
Jaap de Vries 2012년 12월 13일
To whom it may concern:
It is one of those days when apparent simple tasks seem hard for some reason.
I have a continues but highly non smooth dataset of emissivity versus wavelength. I would really like to put this into a (lookup) function so the my dataset (lamda, e), i.e.,
Lamda e
0.25 0.545
0.26 0.556
0.27 0.654
…etc will turn into a function e = f(lamda). This would be very helpful since I can then create a function handle and integrate over certain wavelength regions and perform other operations.
Any suggestions???

채택된 답변

Matt Fig
Matt Fig 2012년 12월 14일
You could use POLYFIT, or the curve fitting toolbox or a simple interpolation.
>> x = 0:.25:5;
>> y = x.^2;
>> f = @(z) interp1(x,y,z); % Lookup table function
>> x2 = 1/8:1/8:5; % Just to compare func to data.
>> plot(x,y,'sb',x2,f(x2),'*r')
  댓글 수: 1
Jaap de Vries
Jaap de Vries 2012년 12월 14일
Perfect Matt, This solved the problem. I preferred the interp1 function since the data is to jagged for a POLYFIT would require too many coefficients. My code now reads
% Import the data from a text file.
ems = importdata('Emmisivity.txt'); %the spectrally resolved emissivity data
Data = ems.data; %Selects the values, neglects the headers
% create a lookup function handle for the data.
specEms = @(lamda) interp1(Data(:,1), Data(:,2),lamda);
% create a function handle for the spectral exitance, a basically the Max
% Planck’s law for a black body.
specExbb = @(lamda, T) specexitance(lamda, T); %funtion created by me.
% create a exitance function for a selective emitter.
specExSel = @(lamda, T) specExbb(lamda, T).*specEms(lamda);
% integrate over a user-specified range (lamda1-lamda2), leave the function
% parameterized with respect to T.
ExSel = @(lamda1, lamda2, T) integral(@(lamda) specExSel (lamda,T),lamda1,lamda2);
Thank you so much, my faith in humanity is ones again restored. Jaap

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

추가 답변 (1개)

Jing
Jing 2012년 12월 13일
Hi Jaap, I can't fully understand your question. Do you mean you want a lookup table in function form? If so, you can use fitting process(The fitting highly depends on the fit type your use) to build a function, but the function may not be very accurate at each data point.

카테고리

Help CenterFile Exchange에서 Biological and Health Sciences에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by