Matlab: How to change the focus between the outer and inner windows?

I hope this is not an easy problem, but I have not yet understood the answer and have not seen a good resource for this. I run an experiment in Matlab, and sometimes we call an external program. After some time, I want the participants to return to Matlab to conduct a survey and then resume their work after they are completed. The problem is that the external code is interactive, so a person can print or click, and not see the poll open, and after the poll is completed I don’t know how to automatically return them to the open program (although I know when they are executed with their poll and automatically close the browser). An example of my toy code:

system('start \max notepad.exe') pause(60) %After x seconds a web page opens up in Matlab, how to ensure users see it? web('cnn.com') %I have code that will close this after they click on a certain link %After close browser, how to return to notepad where they left off? 
+4
source share
1 answer

Two solutions can help you. This is actually a bit complicated. Solution 1 uses the control window using the mex program method using c code. Solution 2 is also getting complicated, just use the MATLAB parallel toolbar. Hmm, I suggest your solution for using 1.


solution 1:

  • Create a cpp file that controls your interactive program (e.g. window explorer here). code below. copy and save the code as "ctrlWindow.cpp" in your current MATLAB folder.

  • compile ctrlWindow.cpp with the lcc compiler:

     mex -setup % choose compiler: type this command at MATLAB command, then choose lcc complier on windows 32 system mex ctrlWindow.cpp % compile cpp: you would find ctrlWindow.mexw32 at current folder 
  • run the mex file as an m file in the MATLAB command:

    ctrlWindow ('your_program_window_name', command);

i.e. the window name of the folder "myfold" is myfold, which is displayed in the upper left corner of the window, enter the command:

 ctrlWindow('myfold',6); 

this minimizes the window of your folder. I suggest you first minimize the program window, and then maximize it, and the participants will again focus on your program:

 ctrlWindow('myfold',6);%minimize window ctrlWindow('myfold',3);%maximize window and participants would focus on this window 

:

 HIDE 0 SHOWNORMAL 1 NORMAL 1 SHOWMINIMIZED 2 SHOWMAXIMIZED 3 MAXIMIZE 3 SHOWNOACTIVATE 4 SHOW 5 MINIMIZE 6 SHOWMINNOACTIVE 7 SHOWNA 8 RESTORE 9 SHOWDEFAULT 10 FORCEMINIMIZE 11 MAX 11 

// File name: ctrlWindow.cpp

 #include <windows.h> #include "mex.h" void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] ) { mxChar* winName; //name of window wanted to be found HWND hwnd; //handle of window int command; //command of control window // check number of input if(nrhs!=2) mexErrMsgTxt("input must be 2"); // check class of input if (mxIsChar(prhs[0])) winName=mxGetChars(prhs[0]);//get name of window else mexErrMsgTxt("input 1 should be char -- name of window"); if (mxIsDouble(prhs[1])) { command = (int) mxGetScalar(prhs[1]);//get command if(command<0 || command >11)//check command mexErrMsgTxt("No such command!!!"); } else mexErrMsgTxt("input 2 should be a double"); // find window hwnd = FindWindowW(NULL, (LPCWSTR)winName); if(NULL==hwnd) { MessageBoxW(NULL,(LPCWSTR) L"Can't find the window!!!",NULL,MB_OK); return; } ShowWindow(hwnd, command);//control the window } 

Solution 2:

 matlabpool open 2 

open two matlab backgrounds, first use your first first program, use the second, control the second program.

+3
source

Source: https://habr.com/ru/post/1446091/


All Articles