Passing variables from one m-file to another

9 views (last 30 days)
I am a beginner in MATLAB, so I would really appreciate any guidance on this seemingly obvious question. I have to minimize a function f(x)[Currently using fmincon]. f(x) has a number of parameters which I want to initialise during the run time itself, and each parameter has its own range. [Currently I am doing it using rand.] So I have created the my_fun file which initialises the parameters and creates the function. Now, how do I pass the values of these parameters to the constraint file?

Accepted Answer

Matt J
Matt J on 23 Mar 2015
Edited: Matt J on 24 Mar 2015
You should not be initializing parameters inside the file that implements your objective function, especially not random ones! That would make the output of your objective function random for any given input x, and therefore impossible to minimize iteratively. You should be initializing all parameters in the workspace of whatever code you have that calls fmincon. Once you've done that, you can pass the parameters both to f(x) and to your constraints using techniques discussed here,

More Answers (0)

Categories

Find more on Variables in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!