function in a GUI does not return the correct value after function's parameters have been modified outside of the GUI
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi all, I have a GUI with external functions that I call inside callbacks of the GUI.
% define_Params() and compute_function() are written outside of the GUI
function params = define_Params();
params.value = 3;
end
% compute from compute_function
function outputdata = compute_function(inputdata, params)
params = define_Params();
outputdata = algo(inputdata, params ) ;
end
In my GUI, I have two callbacks:
1. function compute_pushbutton_Callback(hObject, eventdata, handles) to launch my computation
function apply_to_selectedImages_pushbutton_Callback(hObject, eventdata, handles)
params = define_Params();
outputdata = compute_function(inputdata, params) ;
% update
guidata(hObject, handles);
2. function loadParams_Callback(hObject, eventdata, handles) to load and hopefully to change the parameters for compute_function().
function loadParams_Callback(hObject, eventdata, handles)
...
% open define_Params(), this can be editable
fileattrib( [PathName, FileName],'+w' );
eval(['!"C:\Program Files (x86)\Notepad++\notepad++" ' PathName FileName])
......
% update
guidata(hObject, handles);
which opens define_Params() in Notepad++. And then, I change manually the value of params.value to 10, say, so in that function define_Params() becomes:
function [params] = define_Params()
params.value = 10;
end
I save in Notepad++, and re-launch my compute_pushbutton_Callback():
but the value of params.value is still equal to 3. in params though I changed it to 10. Also, I noticed, that sometimes, it is working and sometimes not ...
Can someone have some explanation about this, please ? And when I use debug mode, though the value is 10, it is still 3 ???
Thank you very much.
채택된 답변
Walter Roberson
2017년 12월 15일
"I have to use Notepad++ since my application will be used with machines without Matlab (standalone application compiled with Matlab Compiler)."
Once a .m file has been compiled by MATLAB Compiler, it is "locked in" to the compiled executable, and changes to it will be ignored. The only way to change the behaviour of a .m that is compiled into an executable is to recompile the executable.
It is a deliberate part of the design of MATLAB Compiler that external .m cannot be evaluated at run-time. MATLAB Compiler is only for "closed" applications that do something specific. If a modifiable .m could be executed at run-time then it would be easy for someone to write a program that just executed an external .m file, compile that, and distribute that, and the effect would be to distribute free MATLAB licenses.
댓글 수: 6
Walter Roberson
2017년 12월 18일
There are also multiple File Exchange contributions that handle ".ini" files, such as
https://www.mathworks.com/matlabcentral/fileexchange/2976-inifile and https://www.mathworks.com/matlabcentral/fileexchange/17177-ini2struct and https://www.mathworks.com/matlabcentral/fileexchange/24992-ini-config that might be acceptable for your purposes. If not, then please describe what kind of settings you need to be able to configure.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Environment and Settings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!