Info

この質問は閉じられています。 編集または回答するには再度開いてください。

how can i share inputs between 2 mfiles??

1 回表示 (過去 30 日間)
Mohamed Ibrahim
Mohamed Ibrahim 2015 年 10 月 7 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
i have 2 .m function files i need to use inputs from one function to the other The inputs value came from PSCAD software. how to do it please??

回答 (2 件)

Walter Roberson
Walter Roberson 2015 年 10 月 7 日
If function F has argument X and F is calling a second function G, then F can just pass X to G
function F(X)
...
G(X)
end
  1 件のコメント
Mohamed Ibrahim
Mohamed Ibrahim 2015 年 10 月 7 日
thanks to your fast response, simply my question is if i have function X that has inputs (a,b). function X call other function Y. All i need that how make function Y calls the values of (a,b) Many thanks

Star Strider
Star Strider 2015 年 10 月 7 日
Without knowing more about the functions, I would pass them as parameters. If one function uses them as inputs and outputs some derived value that other functions use, the first function must return the derived values as outputs, for the other functions to use as arguments (inputs).
PLEASE do not pass them as global variables!
Ambiguous Questions produce ambiguous Answers, so that’s the best I can do.
  2 件のコメント
Mohamed Ibrahim
Mohamed Ibrahim 2015 年 10 月 7 日
thanks to your fast response, simply my question is if i have function X that has inputs (a,b). function X call other function Y. All i need that how make function Y calls the values of (a,b) Many thanks
Star Strider
Star Strider 2015 年 10 月 7 日
Without knowing more, this would be an outline of what I would do, assuming that ‘X’ and ‘Y’ are already defined as functions in your workspace or MATLAB path:
function Q1 = X(a,b)
Q2 = Y(a,b)
Q1 = Q2 ... and whatever operations you want to perform on it;
end
Once you pass (a,b) into ‘X’, they are available to ‘Y’ in this situation.
Then call ‘X’ from your main script workspace:
Q1 = X(a,b);
It will return whatever you told it to.

この質問は閉じられています。

Community Treasure Hunt

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

Start Hunting!

Translated by