modify .m file using a .m file

2 ビュー (過去 30 日間)
Wout Laeremans
Wout Laeremans 2022 年 10 月 12 日
コメント済み: Wout Laeremans 2022 年 10 月 12 日
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 件のコメント
KSSV
KSSV 2022 年 10 月 12 日
What changes you want to make? How the .m file is?
Wout Laeremans
Wout Laeremans 2022 年 10 月 12 日
編集済み: Wout Laeremans 2022 年 10 月 12 日
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.

サインインしてコメントする。

回答 (1 件)

KSSV
KSSV 2022 年 10 月 12 日
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 件のコメント
Wout Laeremans
Wout Laeremans 2022 年 10 月 12 日
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.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

タグ

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by