How to create a function within a function ?
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Dave Martin
am 2 Apr. 2014
Kommentiert: Dave Martin
am 3 Apr. 2014
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 Kommentare
Akzeptierte Antwort
A Jenkins
am 2 Apr. 2014
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
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Data Type Identification finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!