MATLAB: Defining inputs for subfunctions

inputmultiplesubfunction

Hey,
I'm writing some code that involves using set inputs (that I want to be able to change easily) in multiple subfunctions.
Take the following example;
function [ output_args ] = Untitled2( input_args )
clc;
x=0:0.01:5;
plot(f(x),x,g(x),x)
end
function [f_value]=f(x)
speed=6;
f_value=0.5.*speed.*x;
end
function [g_value]=g(x)
speed=6;
g_value=(x.^2)./speed;
end
How would I go about being able to define speed only once and it being 'called up' by any and every subfunction that uses it? I tried looking into nesting but got utterly confused :/ Is there a simple way to do this?

Best Answer

function [ output_args ] = Untitled2( input_args )
speed = 6;
function [f_value]=f(x)
f_value=0.5.*speed.*x;
end
function [g_value]=g(x)
g_value=(x.^2)./speed;
end
x=0:0.01:5;
plot(f(x),x,g(x),x)
end
Related Question