Bring Matlab uigetfile window to front of all other programs? - matlab

I'm calling a script from another program (Vicon Nexus 2.3). This other program will launch Matlab, then run the script.
The first thing the script does is it calls uigetfile(). However since the Nexus program has the Windows focus, the uigetfile() window appears behind everything. Is there any way to bring it to the front without using the mouse?
I've tried:
shg
uistack()
But I think the issue here is windows focus, not uistack. Anyone out there know if this is possible?

What you need to do is bring Matlab to front before opening uigetfile dialogue. You can do that e.g. by calling commandwindow:
commandwindow();
uigetfile();
Tested by starting Matlab from command line and overlaying some other windows on top once it is open, but before the code after pause is executed:
matlab -r "pause(3); commandwindow(); uigetfile();"

Related

How to pause my first MATLAB GUI while the second one is in front

I want to find a solution that pauses the GUI that I created using App Designer in MATLAB.
I mean exactly like uigetfile(), that when you run it you can’t reach the main GUI windows until you close the uigetfile() window.
I need a way to pause my first GUI in the background while my second GUI is in front.
You should set the WindowStyle property of the second figure window to 'modal'. See the documentation for this property.

Matlab2015a freezes when using Psychtoolbox 3.0.10 Screen('Openwindow') in dual display

I'm running a script on a PC (windows 7) with dual monitors, and every time when I open a new on-line window, Matlab freezes (not responding to mouse or keyboard inputs, only to calling windows task manager and switching tasks).
For what I've checked, only Screen('Openwindow') has this problem; other screen functions work fine. This failure never happens in single monitor situation.
Here's my script:
screeninfo.pos = get(0,'MonitorPositions');
if size(screeninfo.pos,1)<2
fprintf('cannot find two monitors! \n');
return;
end
[screeninfo.window, screeninfo.rect] = Screen('OpenWindow',0, [900 900 1000],screeninfo.pos(2,:));
Anyone has a clue?
Psychtoolbox 3.0.10 is ancient. You should update to the latest and greatest.
More importantly, when you open a window, any input (keyboard/mouse) goes to the opened screen, not matlab, unless you specifically focus matlab with alt-tab. cntr+C is an exception that makes matlab stop execution of the script, also when a PTB window is open.
If your matlab is on another screen than where the PTB window is opened, things should work normally. But if you start interacting with the matlab interface which a PTB window is open, all guarantees of proper timing of the PTB window are gone.

How to save the life of my process?

I have the following problem: I want to run a really cumbersome calculation on a server via Putty in Matlab. Now I do not want to keep my notebook the whole time connected to this server, which is why I am searching for a solution to this problem. I know that screen in general works but I am not sure whether this could help me here too. The problem is the following: Each time I start this Matlab program I have no longer control over the terminal, since the Matlab program is still running. Therefore I am always forced to abort the process, which is what I do not want to happen. Is there anything that could help me.
What I need this:
1.)Start Matlab Application on server
2.)Disconnect from Server
3.)Connect to Server
4.)Have access to Matlab again
I would highly appreciate it, if somebody could give me a reference to some commands that might be helpful in this situation.
As #Peter said, screen is one good solution. A brief tutorial:
Connect to server
screen -S SectionName
matlab -nosplash -nodesktop or -nodisplay or -nojvm depending if you have allowed X11 forwarding on putty (you can check this by simply open a figure and check if you can see it with -nodesktop option)
Ctrl+a d to detach
Log out
Reconnect to server
If you are using X11 forwarding, you may need to update your display on the screen, so: echo $DISPLAY, copy its result
screen -rd SectionName
If you are using X11 forward, update display on screen export DISPLAY="value echoed outside screen" (I think the opposite also works, you set the log display into the screen display)
Finish Screen
Exit matlab and type exit
List open screens
screen -ls
Terminate unresponsive screen
Ctrl+a Ctrl+k and answer y
Navigate through screen screen:
Ctrl+esc and then use arrows or: ctrl+u to go half screen up and ctrl+d to half screen down
Exit broken connection screen
~ .
Note: You can have more than one screen section running, or you can open multiple screen windows by using Ctrl+a Ctrl+c
Note2: screen command may be very addicting, use it with cautious. Don't forget to read its man page.

How to run the code without the GUI

I have a rather long perltk code in my hand and I would like to run the simulation in a batch mode (without using the GUI). e.g. I would like to run it with script like "myprog.pl -b" in stead of setting all the parameters in the GUI and click buttons.
My current method is using a separated XML file for config and the function "after" which means the GUI will pop-out and start the simulation then exit after sometime. It is now working, but I have a question: is there a better way solve this problem? Is that possible to have the GUI shown in the background (so we wont see it) in stead of pop-out?
Change the program so it is accessible from both a graphical and command-line interface. Factor out its real functionality into subroutines.
Run the program in an xvfb so that no window is shown on the main display.
Configure the window manager to always start instances of this program minimised and/or with a 0x0 size.

Why does file have to be saved prior to running?

In MATLAB, why does the file have to be saved prior to running ?
I often try quick snippets of code, which I could also easily run also on the Command Window line by line. So, why when I run them through the editor, I have to save them first ?
Can this behaviour be changed, maybe ?
You can use cell mode in the editor placing %% before your code. See also Cell menu in the editor. Once you create cells, you can run them one by one pressing Ctrl-Enter. You don't need to save the file. However you cannot use editor's debugging features (breakpoints, etc).
Video tutorial
my guess would be that when you run your program, the matlab interpreter run it from the disk and not from the IDE buffer. so if you don't save the file it wouldn't run the correct code.