One instance running issue
Show older comments
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)
Answers (1)
Walter Roberson
on 18 Apr 2019
0 votes
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 Comments
duong mai
on 19 Apr 2019
Walter Roberson
on 19 Apr 2019
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
Categories
Find more on Environment and Settings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!