How to create a function within a function ?
10 ビュー (過去 30 日間)
古いコメントを表示
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);
0 件のコメント
採用された回答
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
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Data Type Identification についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!