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일

1 개 추천

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.

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

카테고리

도움말 센터File Exchange에서 MATLAB에 대해 자세히 알아보기

제품

릴리스

R2021a

태그

질문:

2022년 10월 12일

댓글:

2022년 10월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by