Loading Parameters from Text File into Function

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

per isakson
per isakson 2016년 9월 2일
편집: per isakson 2016년 9월 2일
This sounds like a The XY Problem
Try replace
load parameters.m
by
parameters
or maybe better by
run( 'parameters' )
However, ...
I see your point about the XY problem, should I edit my question or post a new one?
I wrote a new question here Thank you for the suggestion

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

도움말 센터File Exchange에서 Workspace Variables and MAT Files에 대해 자세히 알아보기

제품

질문:

2016년 9월 2일

댓글:

2016년 9월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by