Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
two monitors

Subject: two monitors

From: Jessica

Date: 26 Jun, 2008 16:51:02

Message: 1 of 14

Hi,

I am trying to get figures to automatically pop-up on the
second monitor that is attached to my computer. Based on
previous forum topics, I see that using get
(0, "screensize') has been suggested as a way to find the
position of the screen and then use this information to
place the figure. However, when I go this, the output is:

1 1 1024 768.

My first monitor is 1024x768 and my second monitor is
1680x1050. So it appears that the get command is only
processing the first screen.

Does anyone have any ideas to get around this?

Thank!

Subject: two monitors

From: Jomar Bueyes

Date: 26 Jun, 2008 17:06:20

Message: 2 of 14

On Jun 26, 11:51 am, "Jessica " <jyorzin...@ucdavis.edu> wrote:
> Hi,
>
> I am trying to get figures to automatically pop-up on the
> second monitor that is attached to my computer. Based on
> previous forum topics, I see that using get
> (0, "screensize') has been suggested as a way to find the
> position of the screen and then use this information to
> place the figure. However, when I go this, the output is:
>
> 1 1 1024 768.
>
> My first monitor is 1024x768 and my second monitor is
> 1680x1050. So it appears that the get command is only
> processing the first screen.
>
> Does anyone have any ideas to get around this?
>
> Thank!

Hi Jessica,

This is something I got from this newsgroup:

When using more than one monitor (e.g. N monitors) the
positions of the different monitors can be obtained with

> mp = get(0, 'MonitorPositions');

mp is a Nx4 array
mp(1,:) is the position of the primary monitor
mp(k,:) is the position of the k-th monitor.

This can be used instead of the screensize property to
adjust things to the size of the different monitors.

HTH

Jomar

Subject: two monitors

From: Jessica

Date: 26 Jun, 2008 17:40:19

Message: 3 of 14

Jomar Bueyes <jomarbueyes@hotmail.com> wrote in message
<01064b4f-5b94-41ad-bdf6-fd6925e6cd3c@d1g2000hsg.googlegroups.com>...
> On Jun 26, 11:51 am, "Jessica " <jyorzin...@ucdavis.edu>
wrote:
> > Hi,
> >
> > I am trying to get figures to automatically pop-up on the
> > second monitor that is attached to my computer. Based on
> > previous forum topics, I see that using get
> > (0, "screensize') has been suggested as a way to find the
> > position of the screen and then use this information to
> > place the figure. However, when I go this, the output is:
> >
> > 1 1 1024 768.
> >
> > My first monitor is 1024x768 and my second monitor is
> > 1680x1050. So it appears that the get command is only
> > processing the first screen.
> >
> > Does anyone have any ideas to get around this?
> >
> > Thank!
>
> Hi Jessica,
>
> This is something I got from this newsgroup:
>
> When using more than one monitor (e.g. N monitors) the
> positions of the different monitors can be obtained with
>
> > mp = get(0, 'MonitorPositions');
>
> mp is a Nx4 array
> mp(1,:) is the position of the primary monitor
> mp(k,:) is the position of the k-th monitor.
>
> This can be used instead of the screensize property to
> adjust things to the size of the different monitors.
>
> HTH
>
> Jomar

When I use this command, matlab outputs:
1 1 1024 768
-1679 -279 0 770

It seems that 279+770 is close to the resolution of my
second monitor height.

Given this, do you know how I can make an image appear on
that second monitor?

I have both imshow and inputdlg commands that pop-up images
and boxes, respectively. Can I add something to these
commands to make them automatically appear on the second screen?

Thanks!

Subject: two monitors

From: Jomar Bueyes

Date: 26 Jun, 2008 18:00:09

Message: 4 of 14

On Jun 26, 12:40 pm, "Jessica " <jyorzin...@ucdavis.edu> wrote:
> Jomar Bueyes <jomarbue...@hotmail.com> wrote in message
>
> <01064b4f-5b94-41ad-bdf6-fd6925e6c...@d1g2000hsg.googlegroups.com>...
>
>
>
> > On Jun 26, 11:51 am, "Jessica " <jyorzin...@ucdavis.edu>
> wrote:
> > > Hi,
>
> > > I am trying to get figures to automatically pop-up on the
> > > second monitor that is attached to my computer. Based on
> > > previous forum topics, I see that using get
> > > (0, "screensize') has been suggested as a way to find the
> > > position of the screen and then use this information to
> > > place the figure. However, when I go this, the output is:
>
> > > 1 1 1024 768.
>
> > > My first monitor is 1024x768 and my second monitor is
> > > 1680x1050. So it appears that the get command is only
> > > processing the first screen.
>
> > > Does anyone have any ideas to get around this?
>
> > > Thank!
>
> > Hi Jessica,
>
> > This is something I got from this newsgroup:
>
> > When using more than one monitor (e.g. N monitors) the
> > positions of the different monitors can be obtained with
>
> > > mp = get(0, 'MonitorPositions');
>
> > mp is a Nx4 array
> > mp(1,:) is the position of the primary monitor
> > mp(k,:) is the position of the k-th monitor.
>
> > This can be used instead of the screensize property to
> > adjust things to the size of the different monitors.
>
> > HTH
>
> > Jomar
>
> When I use this command, matlab outputs:
> 1 1 1024 768
> -1679 -279 0 770
>
> It seems that 279+770 is close to the resolution of my
> second monitor height.
>
> Given this, do you know how I can make an image appear on
> that second monitor?
>
> I have both imshow and inputdlg commands that pop-up images
> and boxes, respectively. Can I add something to these
> commands to make them automatically appear on the second screen?
>
> Thanks!

Hi Jessica,

This is only a guess (I haven't tried it), but something like the
following might work

fh = imshow(whatever); % place the image wherever
fp = get(fh, 'position'); % get the position of the image
set (fh, 'position', [-1600 -270 fp(3:4) ]); % move the image to the
second monitor

The idea is to place the figure at a point in the second monitor with
the width and height of the original figure.

HTH

Jomar

Subject: two monitors

From: Doug Schwarz

Date: 26 Jun, 2008 19:31:17

Message: 5 of 14

In article <g40ka3$ncf$1@fred.mathworks.com>, "Jessica " <jyorzinski@ucdavis.edu> wrote:

> Jomar Bueyes <jomarbueyes@hotmail.com> wrote in message
> <01064b4f-5b94-41ad-bdf6-fd6925e6cd3c@d1g2000hsg.googlegroups.com>...
> > On Jun 26, 11:51 am, "Jessica " <jyorzin...@ucdavis.edu>
> wrote:
> > > Hi,
> > >
> > > I am trying to get figures to automatically pop-up on the
> > > second monitor that is attached to my computer. Based on
> > > previous forum topics, I see that using get
> > > (0, "screensize') has been suggested as a way to find the
> > > position of the screen and then use this information to
> > > place the figure. However, when I go this, the output is:
> > >
> > > 1 1 1024 768.
> > >
> > > My first monitor is 1024x768 and my second monitor is
> > > 1680x1050. So it appears that the get command is only
> > > processing the first screen.
> > >
> > > Does anyone have any ideas to get around this?
> > >
> > > Thank!
> >
> > Hi Jessica,
> >
> > This is something I got from this newsgroup:
> >
> > When using more than one monitor (e.g. N monitors) the
> > positions of the different monitors can be obtained with
> >
> > > mp = get(0, 'MonitorPositions');
> >
> > mp is a Nx4 array
> > mp(1,:) is the position of the primary monitor
> > mp(k,:) is the position of the k-th monitor.
> >
> > This can be used instead of the screensize property to
> > adjust things to the size of the different monitors.
> >
> > HTH
> >
> > Jomar
>
> When I use this command, matlab outputs:
> 1 1 1024 768
> -1679 -279 0 770
>
> It seems that 279+770 is close to the resolution of my
> second monitor height.
>
> Given this, do you know how I can make an image appear on
> that second monitor?
>
> I have both imshow and inputdlg commands that pop-up images
> and boxes, respectively. Can I add something to these
> commands to make them automatically appear on the second screen?
>
> Thanks!

The MonitorPositions property doesn't seem to return useful
information. I have investigated it on both Mac OS X and
Windows. The solution I came up with is this function,
screensize, which returns the proper coordinates of multiple
screens. I plan on submitting it to the FEX when I get a chance,
but give it a try and let me know how it works out. I need to
add some documentation and work out a few minor details.

To use, just run with no arguments (I only have one screen right now):

  >> screensize
  ans =
             1 0 1920 1200

or pass in the screen number whose coordinates you need:

  >> screensize(2)
  ans =
             1 0 1920 1200

If you don't have that many screens it'll still return the
coordinates of the highest-numbered one.

And here's the function (watch for possible wrapped lines):


------------------ screensize.m ---------------------------
function ss_out = screensize(screen_number)
%screensize: return screen coordinates of multiple monitors.
 
% Version: 1.0, 26 June 2008
% Author: Douglas M. Schwarz
% Email: dmschwarz=ieee*org, dmschwarz=urgrad*rochester*edu
% Real_email = regexprep(Email,{'=','*'},{'@','.'})
 
 
persistent ss
if ~isempty(ss)
    num_screens = size(ss,1);
    if nargin == 0
        screen_number = 1:num_screens;
    end
    screen_index = min(screen_number,num_screens);
    ss_out = ss(screen_index,:);
    return
end
 
% Create an invisible figure (required for get(0,'PointerLocation') to work
% correctly on OS X).
fig = figure('Visible','off');
 
% Get initial location of mouse pointer.
mouse_loc = java.awt.MouseInfo.getPointerInfo.getLocation;
 
% Create a robot to move mouse pointer.
robot = java.awt.Robot;
 
% Get Screen Devices array.
sd = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment.getScreenDevices;
 
% Initialize screensize array.
num_screens = length(sd);
ss = zeros(num_screens,4);
 
% Loop over all Screen Devices.
for i = 1:num_screens
    % Get coordinate bounds of Screen Device.
    bounds = sd(i).getDefaultConfiguration.getBounds;
 
    % Move mouse pointer to lower left corner of this screen and get MATLAB
    % coordinates of that point.
    robot.mouseMove(bounds.x, bounds.y + bounds.height)
    pl_ll = get(0,'PointerLocation');
 
    % Move mouse pointer to upper right corner of this screen and get
    % MATLAB coordinates of that point.
    robot.mouseMove(bounds.x + bounds.width, bounds.y)
    pl_ur = get(0,'PointerLocation');
 
    % Fill in screen size array.
    ss(i,:) = [pl_ll, pl_ur - pl_ll];
end
 
num_screens = size(ss,1);
if nargin == 0
    screen_number = 1:num_screens;
end
screen_index = min(screen_number,num_screens);
ss_out = ss(screen_index,:);
 
% Return mouse pointer to initial location.
robot.mouseMove(mouse_loc.x, mouse_loc.y)
 
% Delete the figure.
delete(fig)
-----------------------------------------------------------------

--
Doug Schwarz
dmschwarz&ieee,org
Make obvious changes to get real email address.

Subject: two monitors

From: Jessica

Date: 27 Jun, 2008 15:16:03

Message: 6 of 14

Doug Schwarz <see@sig.for.address.edu> wrote in message
<see-7C8CAB.15311726062008@news.motzarella.org>...
> In article <g40ka3$ncf$1@fred.mathworks.com>, "Jessica "
<jyorzinski@ucdavis.edu> wrote:
>
> > Jomar Bueyes <jomarbueyes@hotmail.com> wrote in message
> >
<01064b4f-5b94-41ad-bdf6-fd6925e6cd3c@d1g2000hsg.googlegroups.com>...
> > > On Jun 26, 11:51 am, "Jessica " <jyorzin...@ucdavis.edu>
> > wrote:
> > > > Hi,
> > > >
> > > > I am trying to get figures to automatically pop-up
on the
> > > > second monitor that is attached to my computer. Based on
> > > > previous forum topics, I see that using get
> > > > (0, "screensize') has been suggested as a way to
find the
> > > > position of the screen and then use this information to
> > > > place the figure. However, when I go this, the
output is:
> > > >
> > > > 1 1 1024 768.
> > > >
> > > > My first monitor is 1024x768 and my second monitor is
> > > > 1680x1050. So it appears that the get command is only
> > > > processing the first screen.
> > > >
> > > > Does anyone have any ideas to get around this?
> > > >
> > > > Thank!
> > >
> > > Hi Jessica,
> > >
> > > This is something I got from this newsgroup:
> > >
> > > When using more than one monitor (e.g. N monitors) the
> > > positions of the different monitors can be obtained with
> > >
> > > > mp = get(0, 'MonitorPositions');
> > >
> > > mp is a Nx4 array
> > > mp(1,:) is the position of the primary monitor
> > > mp(k,:) is the position of the k-th monitor.
> > >
> > > This can be used instead of the screensize property to
> > > adjust things to the size of the different monitors.
> > >
> > > HTH
> > >
> > > Jomar
> >
> > When I use this command, matlab outputs:
> > 1 1 1024 768
> > -1679 -279 0 770
> >
> > It seems that 279+770 is close to the resolution of my
> > second monitor height.
> >
> > Given this, do you know how I can make an image appear on
> > that second monitor?
> >
> > I have both imshow and inputdlg commands that pop-up images
> > and boxes, respectively. Can I add something to these
> > commands to make them automatically appear on the second
screen?
> >
> > Thanks!
>
> The MonitorPositions property doesn't seem to return useful
> information. I have investigated it on both Mac OS X and
> Windows. The solution I came up with is this function,
> screensize, which returns the proper coordinates of multiple
> screens. I plan on submitting it to the FEX when I get a
chance,
> but give it a try and let me know how it works out. I
need to
> add some documentation and work out a few minor details.
>
> To use, just run with no arguments (I only have one screen
right now):
>
> >> screensize
> ans =
> 1 0 1920 1200
>
> or pass in the screen number whose coordinates you need:
>
> >> screensize(2)
> ans =
> 1 0 1920 1200
>
> If you don't have that many screens it'll still return the
> coordinates of the highest-numbered one.
>
> And here's the function (watch for possible wrapped lines):
>
>
> ------------------ screensize.m ---------------------------
> function ss_out = screensize(screen_number)
> %screensize: return screen coordinates of multiple monitors.
>
> % Version: 1.0, 26 June 2008
> % Author: Douglas M. Schwarz
> % Email: dmschwarz=ieee*org, dmschwarz=urgrad*rochester*edu
> % Real_email = regexprep(Email,{'=','*'},{'@','.'})
>
>
> persistent ss
> if ~isempty(ss)
> num_screens = size(ss,1);
> if nargin == 0
> screen_number = 1:num_screens;
> end
> screen_index = min(screen_number,num_screens);
> ss_out = ss(screen_index,:);
> return
> end
>
> % Create an invisible figure (required for
get(0,'PointerLocation') to work
> % correctly on OS X).
> fig = figure('Visible','off');
>
> % Get initial location of mouse pointer.
> mouse_loc = java.awt.MouseInfo.getPointerInfo.getLocation;
>
> % Create a robot to move mouse pointer.
> robot = java.awt.Robot;
>
> % Get Screen Devices array.
> sd =
java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment.getScreenDevices;
>
> % Initialize screensize array.
> num_screens = length(sd);
> ss = zeros(num_screens,4);
>
> % Loop over all Screen Devices.
> for i = 1:num_screens
> % Get coordinate bounds of Screen Device.
> bounds = sd(i).getDefaultConfiguration.getBounds;
>
> % Move mouse pointer to lower left corner of this
screen and get MATLAB
> % coordinates of that point.
> robot.mouseMove(bounds.x, bounds.y + bounds.height)
> pl_ll = get(0,'PointerLocation');
>
> % Move mouse pointer to upper right corner of this
screen and get
> % MATLAB coordinates of that point.
> robot.mouseMove(bounds.x + bounds.width, bounds.y)
> pl_ur = get(0,'PointerLocation');
>
> % Fill in screen size array.
> ss(i,:) = [pl_ll, pl_ur - pl_ll];
> end
>
> num_screens = size(ss,1);
> if nargin == 0
> screen_number = 1:num_screens;
> end
> screen_index = min(screen_number,num_screens);
> ss_out = ss(screen_index,:);
>
> % Return mouse pointer to initial location.
> robot.mouseMove(mouse_loc.x, mouse_loc.y)
>
> % Delete the figure.
> delete(fig)
>
-----------------------------------------------------------------
>
> --
> Doug Schwarz
> dmschwarz&ieee,org
> Make obvious changes to get real email address.


Thanks for these suggestions. When I run the function, I get
the output:

1 1 1023 767
-1679 -1 1679 1049

I am still not certain how to use these values to have
images and boxes automatically appear at those positions.
When I try: fh=imshow('picture.bmp');set (fh, [-1679 -1
1679 1049]);

I get an error saying that the parameter/value pair
arguments are invalid.

Any other thoughts?

Subject: two monitors

From: Doug Schwarz

Date: 27 Jun, 2008 16:27:44

Message: 7 of 14

In article <g4307j$a08$1@fred.mathworks.com>,
 "Jessica " <jyorzinski@ucdavis.edu> wrote:

> Doug Schwarz <see@sig.for.address.edu> wrote in message
> <see-7C8CAB.15311726062008@news.motzarella.org>...
> > In article <g40ka3$ncf$1@fred.mathworks.com>, "Jessica "
> <jyorzinski@ucdavis.edu> wrote:
> >
> > > Jomar Bueyes <jomarbueyes@hotmail.com> wrote in message
> > >
> <01064b4f-5b94-41ad-bdf6-fd6925e6cd3c@d1g2000hsg.googlegroups.com>...
> > > > On Jun 26, 11:51 am, "Jessica " <jyorzin...@ucdavis.edu>
> > > wrote:
> > > > > Hi,
> > > > >
> > > > > I am trying to get figures to automatically pop-up
> on the
> > > > > second monitor that is attached to my computer. Based on
> > > > > previous forum topics, I see that using get
> > > > > (0, "screensize') has been suggested as a way to
> find the
> > > > > position of the screen and then use this information to
> > > > > place the figure. However, when I go this, the
> output is:
> > > > >
> > > > > 1 1 1024 768.
> > > > >
> > > > > My first monitor is 1024x768 and my second monitor is
> > > > > 1680x1050. So it appears that the get command is only
> > > > > processing the first screen.

[snip]


> Thanks for these suggestions. When I run the function, I get
> the output:
>
> 1 1 1023 767
> -1679 -1 1679 1049
>
> I am still not certain how to use these values to have
> images and boxes automatically appear at those positions.
> When I try: fh=imshow('picture.bmp');set (fh, [-1679 -1
> 1679 1049]);
>
> I get an error saying that the parameter/value pair
> arguments are invalid.
>
> Any other thoughts?

Jessica,

Referring to your original note I see that you want figures to appear on
your second monitor by default and my program only tells you where that
monitor is. The full answer to your question is to set the default
figure position to the appropriate values. Suppose you want your
figures to be 560x420 pixels centered on your second monitor. Put this
line

  set(0,'DefaultFigurePosition',[-1119 314 560 420])

in your startup.m file. Those first two numbers are the coordinates of
the bottom left corner of your figures.

  -1119 = 1680/2 - 560/2 + (-1679)
    314 = 1050/2 - 420/2 + (-1)


What you did above is not correct because fh is an image handle and then
you tried to use set incorrectly. You want to set the position of the
figure, not the image.

--
Doug Schwarz
dmschwarz&ieee,org
Make obvious changes to get real email address.

Subject: two monitors

From: Ian Clarkson

Date: 27 Jun, 2008 16:32:02

Message: 8 of 14

"Jessica " <jyorzinski@ucdavis.edu> wrote in message
<g4307j$a08$1@fred.mathworks.com>...
> Doug Schwarz <see@sig.for.address.edu> wrote in message
> <see-7C8CAB.15311726062008@news.motzarella.org>...
> > In article <g40ka3$ncf$1@fred.mathworks.com>, "Jessica "
> <jyorzinski@ucdavis.edu> wrote:
> >
> > > Jomar Bueyes <jomarbueyes@hotmail.com> wrote in message
> > >
>
<01064b4f-5b94-41ad-bdf6-fd6925e6cd3c@d1g2000hsg.googlegroups.com>...
> > > > On Jun 26, 11:51 am, "Jessica " <jyorzin...@ucdavis.edu>
> > > wrote:
> > > > > Hi,
> > > > >
> > > > > I am trying to get figures to automatically pop-up
> on the
> > > > > second monitor that is attached to my computer.
Based on
> > > > > previous forum topics, I see that using get
> > > > > (0, "screensize') has been suggested as a way to
> find the
> > > > > position of the screen and then use this
information to
> > > > > place the figure. However, when I go this, the
> output is:
> > > > >
> > > > > 1 1 1024 768.
> > > > >
> > > > > My first monitor is 1024x768 and my second monitor is
> > > > > 1680x1050. So it appears that the get command is only
> > > > > processing the first screen.
> > > > >
> > > > > Does anyone have any ideas to get around this?
> > > > >
> > > > > Thank!
> > > >
> > > > Hi Jessica,
> > > >
> > > > This is something I got from this newsgroup:
> > > >
> > > > When using more than one monitor (e.g. N monitors) the
> > > > positions of the different monitors can be obtained with
> > > >
> > > > > mp = get(0, 'MonitorPositions');
> > > >
> > > > mp is a Nx4 array
> > > > mp(1,:) is the position of the primary monitor
> > > > mp(k,:) is the position of the k-th monitor.
> > > >
> > > > This can be used instead of the screensize property to
> > > > adjust things to the size of the different monitors.
> > > >
> > > > HTH
> > > >
> > > > Jomar
> > >
> > > When I use this command, matlab outputs:
> > > 1 1 1024 768
> > > -1679 -279 0 770
> > >
> > > It seems that 279+770 is close to the resolution of my
> > > second monitor height.
> > >
> > > Given this, do you know how I can make an image appear on
> > > that second monitor?
> > >
> > > I have both imshow and inputdlg commands that pop-up
images
> > > and boxes, respectively. Can I add something to these
> > > commands to make them automatically appear on the second
> screen?
> > >
> > > Thanks!
> >
> > The MonitorPositions property doesn't seem to return useful
> > information. I have investigated it on both Mac OS X and
> > Windows. The solution I came up with is this function,
> > screensize, which returns the proper coordinates of multiple
> > screens. I plan on submitting it to the FEX when I get a
> chance,
> > but give it a try and let me know how it works out. I
> need to
> > add some documentation and work out a few minor details.
> >
> > To use, just run with no arguments (I only have one screen
> right now):
> >
> > >> screensize
> > ans =
> > 1 0 1920 1200
> >
> > or pass in the screen number whose coordinates you need:
> >
> > >> screensize(2)
> > ans =
> > 1 0 1920 1200
> >
> > If you don't have that many screens it'll still return the
> > coordinates of the highest-numbered one.
> >
> > And here's the function (watch for possible wrapped lines):
> >
> >
> > ------------------ screensize.m ---------------------------
> > function ss_out = screensize(screen_number)
> > %screensize: return screen coordinates of multiple monitors.
> >
> > % Version: 1.0, 26 June 2008
> > % Author: Douglas M. Schwarz
> > % Email: dmschwarz=ieee*org,
dmschwarz=urgrad*rochester*edu
> > % Real_email = regexprep(Email,{'=','*'},{'@','.'})
> >
> >
> > persistent ss
> > if ~isempty(ss)
> > num_screens = size(ss,1);
> > if nargin == 0
> > screen_number = 1:num_screens;
> > end
> > screen_index = min(screen_number,num_screens);
> > ss_out = ss(screen_index,:);
> > return
> > end
> >
> > % Create an invisible figure (required for
> get(0,'PointerLocation') to work
> > % correctly on OS X).
> > fig = figure('Visible','off');
> >
> > % Get initial location of mouse pointer.
> > mouse_loc = java.awt.MouseInfo.getPointerInfo.getLocation;
> >
> > % Create a robot to move mouse pointer.
> > robot = java.awt.Robot;
> >
> > % Get Screen Devices array.
> > sd =
>
java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment.getScreenDevices;
> >
> > % Initialize screensize array.
> > num_screens = length(sd);
> > ss = zeros(num_screens,4);
> >
> > % Loop over all Screen Devices.
> > for i = 1:num_screens
> > % Get coordinate bounds of Screen Device.
> > bounds = sd(i).getDefaultConfiguration.getBounds;
> >
> > % Move mouse pointer to lower left corner of this
> screen and get MATLAB
> > % coordinates of that point.
> > robot.mouseMove(bounds.x, bounds.y + bounds.height)
> > pl_ll = get(0,'PointerLocation');
> >
> > % Move mouse pointer to upper right corner of this
> screen and get
> > % MATLAB coordinates of that point.
> > robot.mouseMove(bounds.x + bounds.width, bounds.y)
> > pl_ur = get(0,'PointerLocation');
> >
> > % Fill in screen size array.
> > ss(i,:) = [pl_ll, pl_ur - pl_ll];
> > end
> >
> > num_screens = size(ss,1);
> > if nargin == 0
> > screen_number = 1:num_screens;
> > end
> > screen_index = min(screen_number,num_screens);
> > ss_out = ss(screen_index,:);
> >
> > % Return mouse pointer to initial location.
> > robot.mouseMove(mouse_loc.x, mouse_loc.y)
> >
> > % Delete the figure.
> > delete(fig)
> >
>
-----------------------------------------------------------------
> >
> > --
> > Doug Schwarz
> > dmschwarz&ieee,org
> > Make obvious changes to get real email address.
>
>
> Thanks for these suggestions. When I run the function, I get
> the output:
>
> 1 1 1023 767
> -1679 -1 1679 1049
>
> I am still not certain how to use these values to have
> images and boxes automatically appear at those positions.
> When I try: fh=imshow('picture.bmp');set (fh, [-1679 -1
> 1679 1049]);
>
> I get an error saying that the parameter/value pair
> arguments are invalid.
>
> Any other thoughts?

Make sure you identify what parameter you want to set for
fh. Your code above:

set(fh, [-1679 -1 1679 1049]);

doesn't identify a parameter that you're setting -- only the
object. Try this instead:

set(fh, 'Position', [-1679 -1 1679 1049]);

Subject: two monitors

From: Jessica

Date: 30 Jun, 2008 04:21:02

Message: 9 of 14

"Ian Clarkson" <ovoidkumquat@hotmail.com> wrote in message
<g434m2$8bd$1@fred.mathworks.com>...
> "Jessica " <jyorzinski@ucdavis.edu> wrote in message
> <g4307j$a08$1@fred.mathworks.com>...
> > Doug Schwarz <see@sig.for.address.edu> wrote in message
> > <see-7C8CAB.15311726062008@news.motzarella.org>...
> > > In article <g40ka3
$ncf$1@fred.mathworks.com>, "Jessica "
> > <jyorzinski@ucdavis.edu> wrote:
> > >
> > > > Jomar Bueyes <jomarbueyes@hotmail.com> wrote in
message
> > > >
> >
> <01064b4f-5b94-41ad-bdf6-
fd6925e6cd3c@d1g2000hsg.googlegroups.com>...
> > > > > On Jun 26, 11:51 am, "Jessica "
<jyorzin...@ucdavis.edu>
> > > > wrote:
> > > > > > Hi,
> > > > > >
> > > > > > I am trying to get figures to automatically pop-
up
> > on the
> > > > > > second monitor that is attached to my computer.
> Based on
> > > > > > previous forum topics, I see that using get
> > > > > > (0, "screensize') has been suggested as a way to
> > find the
> > > > > > position of the screen and then use this
> information to
> > > > > > place the figure. However, when I go this, the
> > output is:
> > > > > >
> > > > > > 1 1 1024 768.
> > > > > >
> > > > > > My first monitor is 1024x768 and my second
monitor is
> > > > > > 1680x1050. So it appears that the get command
is only
> > > > > > processing the first screen.
> > > > > >
> > > > > > Does anyone have any ideas to get around this?
> > > > > >
> > > > > > Thank!
> > > > >
> > > > > Hi Jessica,
> > > > >
> > > > > This is something I got from this newsgroup:
> > > > >
> > > > > When using more than one monitor (e.g. N
monitors) the
> > > > > positions of the different monitors can be
obtained with
> > > > >
> > > > > > mp = get(0, 'MonitorPositions');
> > > > >
> > > > > mp is a Nx4 array
> > > > > mp(1,:) is the position of the primary monitor
> > > > > mp(k,:) is the position of the k-th monitor.
> > > > >
> > > > > This can be used instead of the screensize
property to
> > > > > adjust things to the size of the different
monitors.
> > > > >
> > > > > HTH
> > > > >
> > > > > Jomar
> > > >
> > > > When I use this command, matlab outputs:
> > > > 1 1 1024 768
> > > > -1679 -279 0 770
> > > >
> > > > It seems that 279+770 is close to the resolution of
my
> > > > second monitor height.
> > > >
> > > > Given this, do you know how I can make an image
appear on
> > > > that second monitor?
> > > >
> > > > I have both imshow and inputdlg commands that pop-up
> images
> > > > and boxes, respectively. Can I add something to
these
> > > > commands to make them automatically appear on the
second
> > screen?
> > > >
> > > > Thanks!
> > >
> > > The MonitorPositions property doesn't seem to return
useful
> > > information. I have investigated it on both Mac OS X
and
> > > Windows. The solution I came up with is this
function,
> > > screensize, which returns the proper coordinates of
multiple
> > > screens. I plan on submitting it to the FEX when I
get a
> > chance,
> > > but give it a try and let me know how it works out. I
> > need to
> > > add some documentation and work out a few minor
details.
> > >
> > > To use, just run with no arguments (I only have one
screen
> > right now):
> > >
> > > >> screensize
> > > ans =
> > > 1 0 1920 1200
> > >
> > > or pass in the screen number whose coordinates you
need:
> > >
> > > >> screensize(2)
> > > ans =
> > > 1 0 1920 1200
> > >
> > > If you don't have that many screens it'll still
return the
> > > coordinates of the highest-numbered one.
> > >
> > > And here's the function (watch for possible wrapped
lines):
> > >
> > >
> > > ------------------ screensize.m ----------------------
-----
> > > function ss_out = screensize(screen_number)
> > > %screensize: return screen coordinates of multiple
monitors.
> > >
> > > % Version: 1.0, 26 June 2008
> > > % Author: Douglas M. Schwarz
> > > % Email: dmschwarz=ieee*org,
> dmschwarz=urgrad*rochester*edu
> > > % Real_email = regexprep(Email,{'=','*'},{'@','.'})
> > >
> > >
> > > persistent ss
> > > if ~isempty(ss)
> > > num_screens = size(ss,1);
> > > if nargin == 0
> > > screen_number = 1:num_screens;
> > > end
> > > screen_index = min(screen_number,num_screens);
> > > ss_out = ss(screen_index,:);
> > > return
> > > end
> > >
> > > % Create an invisible figure (required for
> > get(0,'PointerLocation') to work
> > > % correctly on OS X).
> > > fig = figure('Visible','off');
> > >
> > > % Get initial location of mouse pointer.
> > > mouse_loc =
java.awt.MouseInfo.getPointerInfo.getLocation;
> > >
> > > % Create a robot to move mouse pointer.
> > > robot = java.awt.Robot;
> > >
> > > % Get Screen Devices array.
> > > sd =
> >
>
java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment.get
ScreenDevices;
> > >
> > > % Initialize screensize array.
> > > num_screens = length(sd);
> > > ss = zeros(num_screens,4);
> > >
> > > % Loop over all Screen Devices.
> > > for i = 1:num_screens
> > > % Get coordinate bounds of Screen Device.
> > > bounds = sd(i).getDefaultConfiguration.getBounds;
> > >
> > > % Move mouse pointer to lower left corner of this
> > screen and get MATLAB
> > > % coordinates of that point.
> > > robot.mouseMove(bounds.x, bounds.y +
bounds.height)
> > > pl_ll = get(0,'PointerLocation');
> > >
> > > % Move mouse pointer to upper right corner of this
> > screen and get
> > > % MATLAB coordinates of that point.
> > > robot.mouseMove(bounds.x + bounds.width, bounds.y)
> > > pl_ur = get(0,'PointerLocation');
> > >
> > > % Fill in screen size array.
> > > ss(i,:) = [pl_ll, pl_ur - pl_ll];
> > > end
> > >
> > > num_screens = size(ss,1);
> > > if nargin == 0
> > > screen_number = 1:num_screens;
> > > end
> > > screen_index = min(screen_number,num_screens);
> > > ss_out = ss(screen_index,:);
> > >
> > > % Return mouse pointer to initial location.
> > > robot.mouseMove(mouse_loc.x, mouse_loc.y)
> > >
> > > % Delete the figure.
> > > delete(fig)
> > >
> >
> ----------------------------------------------------------
-------
> > >
> > > --
> > > Doug Schwarz
> > > dmschwarz&ieee,org
> > > Make obvious changes to get real email address.
> >
> >
> > Thanks for these suggestions. When I run the function,
I get
> > the output:
> >
> > 1 1 1023 767
> > -1679 -1 1679 1049
> >
> > I am still not certain how to use these values to have
> > images and boxes automatically appear at those
positions.
> > When I try: fh=imshow('picture.bmp');set (fh, [-1679 -
1
> > 1679 1049]);
> >
> > I get an error saying that the parameter/value pair
> > arguments are invalid.
> >
> > Any other thoughts?
>
> Make sure you identify what parameter you want to set for
> fh. Your code above:
>
> set(fh, [-1679 -1 1679 1049]);
>
> doesn't identify a parameter that you're setting -- only
the
> object. Try this instead:
>
> set(fh, 'Position', [-1679 -1 1679 1049]);
>

Unfortunately, neither

fh=imshow(Picture.bmp');
set(fh, 'Position', [-1679 -1 1679 1049]);

nor

imshow(Picture.bmp');
set(0,'DefaultFigurePosition',[-1119 314 560 420])


make the picture appear on the second monitor. The picture
still pops-up on the first monitor.

Subject: two monitors

From: Doug Schwarz

Date: 30 Jun, 2008 05:53:48

Message: 10 of 14

In article <g49mve$kvp$1@fred.mathworks.com>,
 "Jessica " <jyorzinski@ucdavis.edu> wrote:

>
> Unfortunately, neither
>
> fh=imshow(Picture.bmp');
> set(fh, 'Position', [-1679 -1 1679 1049]);

This doesn't work because fh is a handle to an image object which does
not have a Position property.


>
> nor
>
> imshow(Picture.bmp');
> set(0,'DefaultFigurePosition',[-1119 314 560 420])
>
>
> make the picture appear on the second monitor. The picture
> still pops-up on the first monitor.

This doesn't work because you need to set the DefaultFigurePosition
*before* you create a new figure with imshow. Simply reverse the order
of these two commands. Better yet, put the set command in your startup
file like I said before (and run it or restart MATLAB) and all new
figures will be created on your second monitor.

--
Doug Schwarz
dmschwarz&ieee,org
Make obvious changes to get real email address.

Subject: two monitors

From: Gwendolyn Fischer

Date: 30 Jun, 2008 08:42:02

Message: 11 of 14

Hello,

I've a similar problem.

According to the tips in this thread, I figured out my
screen sizes.

I do not want to setup the DefaultFigurePosition in a
startup file, as I use this only for one project. So I
follow the advice in

<SNIP>
> > imshow(Picture.bmp');
> > set(0,'DefaultFigurePosition',[-1119 314 560 420])
> [...]
> This doesn't work because you need to set the
DefaultFigurePosition
> *before* you create a new figure with imshow. Simply
reverse the order
> of these two commands. Better yet, put the set command
in your startup
> file like I said before (and run it or restart MATLAB)
and all new
> figures will be created on your second monitor.
>
<SNAP>

but still the figures show up on the first screen, moved as
far to the right as possible.

Using a set(gcf,'Position',newPosition) command on the
figure works to move the figure to the second screen, so I
could live with this solution, but 2 things are boggling me:

- Why does the defaultFigurePosition property not work

- I would like to getframe the figure from the second
screen in order to create a movie, but the command fails
with a

??? Error using ==> capturescreen
The rectangle passed to getframe must be at least partially
on screen.

Error in ==> getframe at 35
  x=capturescreen(varargin{:});

Does anyone have a solution for this? (Despite the Psycho
Toolbox, which I'm not allowed to use/install on my system.

Thank you

Gwen

Subject: two monitors

From: Jessica

Date: 30 Jun, 2008 18:06:01

Message: 12 of 14

"Gwendolyn Fischer" <gwendolyn.fischer@nowhere.com> wrote in
message <g4a68q$g4q$1@fred.mathworks.com>...
> Hello,
>
> I've a similar problem.
>
> According to the tips in this thread, I figured out my
> screen sizes.
>
> I do not want to setup the DefaultFigurePosition in a
> startup file, as I use this only for one project. So I
> follow the advice in
>
> <SNIP>
> > > imshow(Picture.bmp');
> > > set(0,'DefaultFigurePosition',[-1119 314 560 420])
> > [...]
> > This doesn't work because you need to set the
> DefaultFigurePosition
> > *before* you create a new figure with imshow. Simply
> reverse the order
> > of these two commands. Better yet, put the set command
> in your startup
> > file like I said before (and run it or restart MATLAB)
> and all new
> > figures will be created on your second monitor.
> >
> <SNAP>
>
> but still the figures show up on the first screen, moved as
> far to the right as possible.
>
> Using a set(gcf,'Position',newPosition) command on the
> figure works to move the figure to the second screen, so I
> could live with this solution, but 2 things are boggling me:
>
> - Why does the defaultFigurePosition property not work
>
> - I would like to getframe the figure from the second
> screen in order to create a movie, but the command fails
> with a
>
> ??? Error using ==> capturescreen
> The rectangle passed to getframe must be at least partially
> on screen.
>
> Error in ==> getframe at 35
> x=capturescreen(varargin{:});
>
> Does anyone have a solution for this? (Despite the Psycho
> Toolbox, which I'm not allowed to use/install on my system.
>
> Thank you
>
> Gwen



Hi,

Yes, the set(gcf,'Position',newPosition) makes it so the
images appear on the second screen. However, they are quite
small-- is there a way to specify for them to be shown at
their full size (their size would be the exact same
dimensions of the second screen)?

Also, this set command doesn't seem to work for inputdlg
boxes. Is there another command for this?

Thanks!

Subject: two monitors

From: Pacho Hybsky

Date: 12 Oct, 2014 10:04:17

Message: 13 of 14

Hi,
I've a similar problem, I want to display an output on secondary monitor. I got the position of the second monitor, put it to vector 'newposition' but using commands

figure(1);
set(gcf,'Position',[1367 -255 M N]);
imshow(result,[b c],'border','tight')

the image is displayed on the primary screen on the right. I observed that the image is displayed on the secondary screen too, but for very short time an then is displayed on primary screen. Can you help me with it?
Thanks

Subject: two monitors

From: Steven Lord

Date: 13 Oct, 2014 14:40:47

Message: 14 of 14


"Pacho Hybsky" <prvadr@jakubb.eu> wrote in message
news:m1djn1$hk3$1@newscl01ah.mathworks.com...
> Hi,
> I've a similar problem, I want to display an output on secondary monitor.
> I got the position of the second monitor, put it to vector 'newposition'
> but using commands
> figure(1);
> set(gcf,'Position',[1367 -255 M N]);
> imshow(result,[b c],'border','tight')
>
> the image is displayed on the primary screen on the right. I observed that
> the image is displayed on the secondary screen too, but for very short
> time an then is displayed on primary screen. Can you help me with it?

The first line tells MATLAB to create a figure with default property
values -- including Position. Then the second line changes the Position
property. What you want to do is to create the figure with the final
Position from the start of its existence. To do so, you can pass the
parameter name/value pair into FIGURE directly.

    figure('Position',[1367 -255 M N]);

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us