Info

This question is closed. Reopen it to edit or answer.

Is it possible to write 4 functions in one file and call them individually?

1 view (last 30 days)
I have to write a program which requires function calling six times. These functions are essentially the same- all the equations are same- except one constant in the equations is being changed six times and the resultant solutions are stored in the script file.
Is it somehow possible to write the 6 functions in the same .m file and then call one each individually in the 6 cases? or do i need to write 6 functions just for that one, single changed constant and call those 6 files?
Also, is there some way to save the constants in an array inside the file but only use one value of the array in one call?
(I call the function to solve the 3 equations inside using ode15s function)

Answers (2)

Matt J
Matt J on 22 Aug 2015
Sounds like an object oriented approach is called for, something like below. If you're not familiar with classdef, you'll have some fun reading to do here,
classdef RelatedEquations
properties
constants
end
methods
function obj=RelatedEquations(input)
obj.constants=input;
end
function output=theEquation(obj,i)
constant=obj.constants(i);
output=....
end
end
end

Matt J
Matt J on 22 Aug 2015

Community Treasure Hunt

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

Start Hunting!