How to create a function within a function ?

5 visualizaciones (últimos 30 días)
Dave Martin
Dave Martin el 2 de Abr. de 2014
Comentada: Dave Martin el 3 de Abr. de 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);

Respuesta aceptada

A Jenkins
A Jenkins el 2 de Abr. de 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

Más respuestas (0)

Categorías

Más información sobre Data Type Identification en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by