フィルターのクリア

Want to return multiple variables from one function to another. How to do so?

1 回表示 (過去 30 日間)
Agam Srivastava
Agam Srivastava 2016 年 2 月 26 日
コメント済み: Ralf 2016 年 3 月 18 日
I have two functions. One function have commands for execution and one function provides input arguments and displays result. Sample code is like this
function [w,,x,y,z]=fn1(a,b)
w=a+b;
x=a-b;
y=a*b;
z=a/b;
end
function [a,b]=fn2(w,x,y,z)
a=5;
b=3;
fn1(a,b); %fn1 called
disp(w);
disp(x);
disp(y);
disp(z);
end
The problem is that the fn1 is not executing and giving error of not enough input arguments for a & b. I am not able to get to how to do so, or any additional command are needed to execute this. Pls help.

採用された回答

Ralf
Ralf 2016 年 2 月 26 日
I am not really sure about what you want to achieve.
At least this code is doing something:
function [a,b]=fn2()
a=5;
b=3;
[w,x,y,z] = fn1(a,b); %fn1 called
disp(w);
disp(x);
disp(y);
disp(z);
end
function [w,x,y,z]=fn1(a,b)
w=a+b;
x=a-b;
y=a*b;
z=a/b;
end
Simply put it in a file named fn2.m and call fn2() from the command line.
  2 件のコメント
Agam Srivastava
Agam Srivastava 2016 年 2 月 26 日
編集済み: Agam Srivastava 2016 年 2 月 26 日
I tried to implement your solution but it is not working. I have hereby attached my program. Its a basic ac dc load flow. Input argument is provided in newton.m file and results are also displayed in same. Program execution is taking place in dclf.m Basically Etr and Eti value are not getting passed from newton.m to dclf.m Appreciate your help :-)
Ralf
Ralf 2016 年 3 月 18 日
I am not sure if I understand your problem correctly. I tried your code and it seemed to work fine. The parameters Etr and Eti are passed to dclf.m without any problem.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeImage Processing Toolbox についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by