MATLAB: How to open the Scope in a Simulink model at a desired position by default in a Dual Monitor setup

callbacksfiguremodelposition;propertiesscopesimulink

I have a dual-monitor setup and everytime I open a Scope in my model, I wish to see it in a particular location on the Secondary monitor, which (Scope) by default opens in the primary.

Best Answer

There is no direct method to move the Scope around but to obtain the Scope handles and then modify the handle properties as you would do for a generic MATLAB 'Figure' window. For the purposes of placing figures on a dual-monitor system, each monitor forms an area of a larger canvas formed by "joining" the two screens. Setting the 'Position' property appropriately will place the Figure (or Scope) on one screen or the other. Please follow the steps below to achieve this:
1) Open the model and keep the scope window open and move it the position on the monitor where you desire it appear every time.
2) Execute the commands
set(0,'ShowHiddenHandles','On') ;
get(gcf,'Position')
at the MATLAB command prompt. this will return a 1x4 position vector where the first two values are the x and y co-ordinates of the left-bottom edge of the Scope (with left-bottom corner of primary screen as origin). For instance you may obtain a row vector, say:
18 57 324 239
3) Now the above vector defines the desired position of your Scope. To set this position, please add the code below to the 'PostLoadFcn' callback. To do so, right-click anywhere on the Simulink model window -> Select 'Model Properties' -> Go to 'Callbacks' pane -> in the 'PostLoadFcn' section add the following code:
a=find_system(gcs,'Name','Scope');
set_param(a{1},'Open','on');
shh = get(0,'ShowHiddenHandles');
set(0,'ShowHiddenHandles','On');
set(gcf,'Position',[18 57 324 239]);
set(0,'ShowHiddenHandles',shh);
Please note:
  • If your scope block has a different name, please modify the line 1 accordingly.
  • Also, in Line 4, the position vector needs to be set with the value that you obtain on your command prompt when executing Step 2 above.