フィルターのクリア

send variable to workspace

10 ビュー (過去 30 日間)
ihab
ihab 2016 年 10 月 18 日
コメント済み: ihab 2016 年 11 月 25 日
i have a code starting with a function, the only variable i get in the workspace is 'ans'. i have other variables inside my code and want to send them to workspace. how can i send variables from the function code to the work space?

回答 (2 件)

Kojiro Saito
Kojiro Saito 2016 年 10 月 18 日
Please set multi variables to the outputs of your function, for example,
function [a, b] = sum_test(a1, a2)
a = a1 + a2;
b = a1 - a2;
a and b is output variables of the function.
And call this function from command window,
[a, b] = sum_test(1, 2)
a =
3
b =
-1
Two output variables will return.
  1 件のコメント
ihab
ihab 2016 年 11 月 25 日
thanks very much

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


Geoff Hayes
Geoff Hayes 2016 年 10 月 18 日
ihab - if there are variables in your function that you wish to return with your function, then update the output parameter list with these variables (see Declare function name, inputs, and outputs. For example, if you have three variables in your function body, say x, y, and z that you wish to return then your function signature would looks something like
function [x,y,z] = myFunction(a,b,c)
The body of myFunction would then initialize the output parameters and perhaps update them as the code executes. At the command line, you would call this function as
>> [x,y,z] = myFunction(1,2,3)
so that the output is assigned to the three output parameters.

カテゴリ

Help Center および File ExchangeWorkspace Variables and MAT-Files についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by