How to write this fuction in Matlab? I have an example code in Python
Ältere Kommentare anzeigen
How to write this fuction in Matlab?

Someone wrote it in Python like this:
def b(r):
return b_1 - (b_1 - b_2) / (r_2 - r_1) * (r - r_1)
Akzeptierte Antwort
Weitere Antworten (2)
Hi, your function contains four parameters, so the python code is incomplete. You can do this several ways in MATLAB, classic syntax would be:
% Test call
myVar = bFunName(10)
% function definition
function b = bFunName(r)
b_1 = 1;
b_2 = 2;
r_2 = 3;
r_1 = 4;
b = b_1 - (b_1 - b_2) / (r_2 - r_1) * (r - r_1);
end
Luca Ferro
am 25 Jan. 2023
1 Stimme
b= @(r) b1 - ((b1-b2)*(r-r1))/(r2 -r1);
where b1,b2,r1,r2 are constants
Kategorien
Mehr zu Call Python from MATLAB finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!