modify .m file using a .m file

1 visualizzazione (ultimi 30 giorni)
Wout Laeremans
Wout Laeremans il 12 Ott 2022
Commentato: Wout Laeremans il 12 Ott 2022
I have a .m file called ilap.m and I need to change one line of this code inside of another .m file, called main.m. I know that similar questions have been asked before, but I have no experience doing something like this, so I do not understand these explanations. Therefore, it would be nice if someone could show me an easy example so that I could understand how to perform this task.
Thanks in advance!
  2 Commenti
KSSV
KSSV il 12 Ott 2022
What changes you want to make? How the .m file is?
Wout Laeremans
Wout Laeremans il 12 Ott 2022
Modificato: Wout Laeremans il 12 Ott 2022
The m. file has the following form:
function F = ilap(p)
a = 1;
k = 11*3.9/0.44^2;
k_plus = 5;
k_on = k_plus;
k_onstar = k_on/a^2;
w = 20*a;
D_f = a^2*k;
k_off = 0.5;
F_eq = k_off./(k_onstar + k_off);
C_eq = k_onstar./(k_onstar + k_off);
F = 1./p - F_eq./p.*(1 - 2.*besselk(1,sqrt(p./D_f.*(1 + k_onstar./(p+k_off))).*w).*besseli(1,sqrt(p./D_f.*(1 + k_onstar./(p+k_off))).*w)).*(1+k_onstar./(p+k_off)) - C_eq./(p+k_off);
This m.file is used as an input for main.m, but within main.m, I want to do a forloop over 'k_off', so I need to be able to change the value of 'k_off' in main.m while running it.

Accedi per commentare.

Risposte (1)

KSSV
KSSV il 12 Ott 2022
So you make k_off as an input to the function and call it in a loop.
% Main function
k_off = 0:0.1:1 ;
m = length(k_off) ;
F = zeros(m,1) ;
p = rand ;
for i = 1:m
F(i) = ilap(p,k_off(i)) ;
end
plot(k_off,F)
function F = ilap(p,k_off)
a = 1;
k = 11*3.9/0.44^2;
k_plus = 5;
k_on = k_plus;
k_onstar = k_on/a^2;
w = 20*a;
D_f = a^2*k;
% k_off = 0.5; % This is made as input
F_eq = k_off./(k_onstar + k_off);
C_eq = k_onstar./(k_onstar + k_off);
F = 1./p - F_eq./p.*(1 - 2.*besselk(1,sqrt(p./D_f.*(1 + k_onstar./(p+k_off))).*w).*besseli(1,sqrt(p./D_f.*(1 + k_onstar./(p+k_off))).*w)).*(1+k_onstar./(p+k_off)) - C_eq./(p+k_off);
end
  1 Commento
Wout Laeremans
Wout Laeremans il 12 Ott 2022
Hi, thanks for your answer, but I need ilap.m to only have 'p' as a variable. This is becaus ilap.m defines in inverse laplace transform and in main.m, I am making use in invlap.m [Hollenbeck, K. J. (1998) INVLAP.M: A matlab function for numerical inversion of Laplace transforms by the de Hoog algorithm, http://www.isva.dtu.dk/staff/karl/invlap.htm] to invert it, which requires an input function with one variable only.

Accedi per commentare.

Categorie

Scopri di più su MATLAB in Help Center e File Exchange

Tag

Prodotti


Release

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by