[QA]How to load parameter in *.m file by matlab script into workspace
17 ビュー (過去 30 日間)
古いコメントを表示
Binh Huynh Thanh
2019 年 4 月 12 日
コメント済み: Binh Huynh Thanh
2019 年 4 月 12 日
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
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()?
採用された回答
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
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
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Interactive Control and Callbacks についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!