How to create a function within a function ?

10 ビュー (過去 30 日間)
Dave Martin
Dave Martin 2014 年 4 月 2 日
コメント済み: Dave Martin 2014 年 4 月 3 日
i have two scripts with a function on each but i need the two functions to run on one script. My two functions are as follows:
function f = OscillationsofStr( x )
% Input:
% x = the co-ordinate of the point
% Data
% Output:
% f=x*sin(x)+cos(x)
f=x*sin(x)+cos(x);
end
function alpha=solEquation()
% Data
alphaIni=0;
alphaEnd=4;
% The oscillations of the Structure function
alpha=fzero(@OscillationsofStr,[alphaIni,alphaEnd],1);

採用された回答

A Jenkins
A Jenkins 2014 年 4 月 2 日
If you want them to reside in one file, you need to switch the order, so that the calling (main) function is before the called (local) function.
function alpha=solEquation()
% Data
alphaIni=0; alphaEnd=4;
% The oscillations of the Structure function
alpha=fzero(@OscillationsofStr,[alphaIni,alphaEnd],1);
end
function f = OscillationsofStr( x )
% Input: % x = the co-ordinate of the point % Data
% Output: % f=x*sin(x)+cos(x)
f=x*sin(x)+cos(x);
end
  1 件のコメント
Dave Martin
Dave Martin 2014 年 4 月 3 日
Thank you very much you hero :)

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Identification についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by