One instance running issue
5 次查看(过去 30 天)
显示 更早的评论
Hello everyone. I am designing an application, which every time that the user run excutive file, the last screen (or the current screen) will pop up, instead of opening new window.
At here, I try to use global variable current_section and my main program is return_to_section.m. Inside each gui program, this global variable is assigned to a specific value (from 0 to 3).
function return_to_section()
global current_section
if current_section==0
figure(main_screen());
return
elseif current_section==1
figure(first());
return
elseif current_section==2
figure(second());
return
elseif current_section==3
figure(third());
return
elseif isempty(current_section)==1
main_screen();
end
When I run the code in debug mode of matlab, it works well and satisfies my requirement. But when I deploy this into an application and run it, the new screen (main_screen) is opened every time I run the excutive file.
Could someone tell me why and how can I overcome this situation. Thanks you in advance. (All the files are attached below, If you want to run the app, you might need to install mcr version 9.0.1 from matlab 2016a)
0 个评论
回答(1 个)
Walter Roberson
2019-4-18
Each run of the compiled executable is a separate process. The global variable will be destroyed between runs, same as if you had quit and reentered MATLAB for the interactive version. You would need to store the information about the last screen in some file (or in the registry, I suppose).
You just might be able to take advantage of setpref()... I have not explored whether that works in a compiled environment.
2 个评论
Walter Roberson
2019-4-19
The preferences are stored in the directory returned by prefdir(), in file matlabprefs.mat
prefdir() is a built-in, so I do not know what it chooses for executables. https://www.mathworks.com/help/matlab/ref/prefdir.html
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!