필터 지우기
필터 지우기

[QA]How to load parameter in *.m file by matlab script into workspace

조회 수: 17 (최근 30일)
Hello Everyone,
I have a ***.m file (Parameter.m).
In the Parameter.m file. I defined CONST_PARAM = 5;
And I had other script file: CallParam()
function CallParam()
run('Parameter.m')
end
But when I run the function CallParam, the parameter CONST_PARAM did not be included into workspace.
The other hand, if you have a other suggestion please tell me.
Please help me.... I am trouble with this problem.
Thank you very much.
  댓글 수: 2
madhan ravi
madhan ravi 2019년 4월 12일
편집: madhan ravi 2019년 4월 12일
Why do you have the need to create CallParam() function in the first place? , why not directly run the script using run()?
Binh Huynh Thanh
Binh Huynh Thanh 2019년 4월 12일
Because, currently I am wring a tool and it will call a lot of different Parameter files for different condition. And above is the problem I would to help.

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

채택된 답변

Alex Mcaulley
Alex Mcaulley 2019년 4월 12일
The function callParam doesn't have any output variable. Then you need something like
function CONST_PARAM = CallParam
run('Parameter.m')
end
And then call the function:
CONST_PARAM = CallParam;
  댓글 수: 5
Alex Mcaulley
Alex Mcaulley 2019년 4월 12일
I don't understand why you are using an script to load variables. There are better options like save them in a mat file and then load them in your CallParam function.
By the way, if you still want to do it in the same way, one option is to define all the variables in a struct (data):
data.CONST_PARAM = 5;
data.CONST_PAR = 1;
data.CONST_PAMJF = 2;
data.CONST_PARIEJFI = 3; %and so on
And then, in you function:
function data = CallParam
run('Parameter.m')
end
Binh Huynh Thanh
Binh Huynh Thanh 2019년 4월 12일
Thank you very much Alex Mcaulley.
Your answer solved my trouble.
@Because this function for testing automatically.
each parameter file is load, test result is different.
By the way, thank again.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by