How to make the contents available in a function for calculation in another function

1 回表示 (過去 30 日間)
Dear all,
Thanks for your time.
I am working on a function as an example:
function [a]=b a=[1 2 3] end
and I would like to make this 'a' matrix available for calculation in another function,which as
function [e,f]=d c=a+b e=c*1 end
However, I always received an error message as Undefined function or variable 'a'.I don't really understand why this happened and how to solve this problem.
Thank you very much.
Zhe Li
  1 件のコメント
José-Luis
José-Luis 2013 年 1 月 8 日
編集済み: José-Luis 2013 年 1 月 8 日
You need to pass a to the other function then.

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

採用された回答

José-Luis
José-Luis 2013 年 1 月 8 日
First function:
function [a] = b
a = [1 2 3];
Second function:
function [e,f] = d(foo); %You need to pass an argument to this function
c = a + foo; %or whatever
e = something;
f = something_else + a;
Then in your script you call the function d as follows:
[e,f] = d(b);

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by