Is it possible to use outcomes of functions in another script, without running that function first?

1 回表示 (過去 30 日間)
Hello,
I had a question about functions. I've a lot of equations and the outcomes of some equations are needed for other equations, like a = 3 + 1 --> b = 2 + a.
To create a better overview I want to try to make 2 scripts. In one I will solve the "basic" equations, script 1, and in the other one the more "advanced" equations, script 2. But, how do I call the outcomes from script 1 into script 2 without running script 1 first? Or isn't this possible?
To make the story a bit more clear I've added a simplified example:
function [Alpha, Beta, Gamma] = basic(x,y)
Alpha = x^2 - 20;
Beta = (x+3)/21;
Gamma = 30*x - 5;
end
And script 2:
function [Outcome1, Outcome2] = advanced(x,y)
Outcome1 = Alpha/Beta * x^2 - 2;
Outcome2 = Gamma/y + Alpha * x;
end
Thanks in advance.
Kind regards,
Danny
  3 件のコメント
Danny Helwegen
Danny Helwegen 2020 年 4 月 30 日
Yes, that is exactly what I was looking for. I just couldn't remember how I was supposed to tell my second function what alpha and beta were. Thanks for the help, my problem is solved.
Tommy
Tommy 2020 年 4 月 30 日
編集済み: Tommy 2020 年 4 月 30 日
Fantastic, happy to help!
(edit) moved above comment to an answer

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

採用された回答

Tommy
Tommy 2020 年 4 月 30 日
You can call your first function in your second function like so:
function [Outcome1, Outcome2] = advanced(x,y)
[Alpha, Beta, Gamma] = basic(x,y);
Outcome1 = Alpha/Beta * x^2 - 2;
Outcome2 = Gamma/y + Alpha * x;
end

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by