Loading Parameters from Text File into Function

3 Ansichten (letzte 30 Tage)
Michael Vaiana
Michael Vaiana am 2 Sep. 2016
Kommentiert: Michael Vaiana am 2 Sep. 2016
I would like to us a .m text file to load parameters into a function. In my real example I have many parameters so I'd like to avoid needing to type them into the function call, I'd rather load them from a txt file. For example:
parameters.m
a=1;
b=2;
c=3;
Then I want to do something like this
function result=myfunc()
load parameters.m
result = a+b+c
end
The only solution I've found is to first run parameters.m as a script, save the workspace variables to a .mat file and then load the matfile, but this is very round about and wastes space by creating the .mat file. Are there other solutions?
  3 Kommentare
Michael Vaiana
Michael Vaiana am 2 Sep. 2016
I see your point about the XY problem, should I edit my question or post a new one?
Michael Vaiana
Michael Vaiana am 2 Sep. 2016
I wrote a new question here Thank you for the suggestion

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Workspace Variables and MAT Files finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by