calling function from separate document for fitting
Mostra commenti meno recenti
Hi all, I am working on this curve fitting project and I am trying out different methods to optimise the run time. One of the methods I am trying involes having 2 seperate scripts, with one script containing the function used for fitting and curve fitting (call this script 1), and the other script containing codes to load the data and process the data (call this script 2). However, when I try to call script 1 from 2, I get a ton of error messages. Could I please ask why is this the problem? Thank you! My codes are attached below:
tic
%% Preparation
clc; clear
format short
TAdata = readmatrix("FCPIB-293K-2.5mW-400nm-Jan072021 -ibg -bg -chirp.csv"); % insert file path within parenthesis
MBdata = readmatrix("carrier temp.xlsx");
P = load("Steady_State_Parameter_Values.mat");
Function = 'Transient_Absorption';
%% Preamble
% Fundamental constants
h = 4.1356677*10^-15; % units: eV/ Hz
c = 3*10^8; % SI units
kB = 8.617333268*10^-5; % units: eV/ K
% Data
Wavelength = TAdata(:, 1);% units: nm
E = (h*c)./(Wavelength*10^-9);
delay_t = TAdata(1, :);
delay_T = MBdata(:, 2);
carrier_T = MBdata(:, 3);
% Data for fitting
min_E = 1.5;
max_E = 2.0;
Range_E = E >= min_E & E <= max_E;
Range_W = Wavelength >= (h*c)/(max_E*10^-9) & Wavelength <= (h*c)/(min_E*10^-9);
E_p = E(Range_E); % selected probe energies
for n = 1:length(carrier_T)
a(1, n) = find(delay_T(n) == delay_t);
data_new2 = TAdata(Range_W, a);
end
%% Data for fitting and calling fitting function & solver
for i = 1:length(delay_T)
p = P.p;
A1 = p(1,1);
A2 = p(1,2);
Eg = p(1,3);
Eb = p(1,4);
R = p(1,5);
g = p(1,6);
deltaAbs = data_new2(:, i);
lb = [0, 0, 0, 0.3, 0, 0]; ub = [20, 0.05, 0.05, 2, 2, 1];
x0 = [1.6244, 0.0346, 0.03, 1.5139, 1, 0.3];
carrierT = carrier_T(i);
[x] = TA_fitting_function(A1, A2, Eg, Eb, R, g, x0,x,carrierT,E_p,deltaAbs,lb,ub,i,LegendText, Function);
end
%% Table of parameter values
time_delay = ['0.5 ps'; '1.0 ps'; '2.0 ps'; '4.0 ps'];
Eg_prime = x(:, 1);
Eb_prime = x(:, 2);
g_prime = x(:, 3);
Ef_q = x(:, 4);
f1 = x(:, 5);
f2 = x(:, 6);
T = table(time_delay, Eg_prime, Eb_prime, g_prime, Ef_q, f1, f2);
disp(T)
toc
Risposta accettata
Più risposte (1)
Divyajyoti Nayak
il 19 Lug 2024
Modificato: Divyajyoti Nayak
il 19 Lug 2024
0 voti
Hi @Jack, the error that you are recieving is because you are passing 'x' as an argument of 'TA_fitting_function' but not defining it anywhere in the script.
Hope that helps!
Categorie
Scopri di più su Get Started with Curve Fitting Toolbox in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!