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:
Christmas Gimmick - random numbers

Subject: Christmas Gimmick - random numbers

From: Ulrik Nash

Date: 10 Dec, 2012 09:33:08

Message: 1 of 4

Hi Everyone,

My department's Christmas party is coming up, and I have the duties for seating arrangements. To make people mix and mingle a little more than usual, I wish to create a simple program, which draws two numbers at random from a list of participants, every X minutes. This will prompt the two corresponding participants to swap seats (actually, they will meet at the front of the dining hall, pour a glass of snaps, say cheers, and then swap seats!).

My questions is, can this be done using MATLAB? Ideally the numbers should be shown on a Christmas image background.

I really appreciate your help/advice.

Subject: Christmas Gimmick - random numbers

From: Ulrik Nash

Date: 10 Dec, 2012 13:37:07

Message: 2 of 4

"Ulrik Nash" <uwn@sam.sdu.dk> wrote in message <ka4a8k$gju$1@newscl01ah.mathworks.com>...
> Hi Everyone,
>
> My department's Christmas party is coming up, and I have the duties for seating arrangements. To make people mix and mingle a little more than usual, I wish to create a simple program, which draws two numbers at random from a list of participants, every X minutes. This will prompt the two corresponding participants to swap seats (actually, they will meet at the front of the dining hall, pour a glass of snaps, say cheers, and then swap seats!).
>
> My questions is, can this be done using MATLAB? Ideally the numbers should be shown on a Christmas image background.
>
> I really appreciate your help/advice.

Okay, so far so good. I would really appreciate if someone could tell me how to implement a background image.

for i = 1:N
% Display area
display_area = uicontrol('Style','text','Position',[0 0 500 400]);

% Static text:
man_text={'Would these MEN please come to the front, propose a toast, and then change seats!'};
static_men = uicontrol('Style','text','Position',[0 350 500 25]);
set(static_men,'String',man_text);

woman_text={'Would these WOMEN please come to the front, propose a toast, and then change seats!'};
static_women = uicontrol('Style','text','Position',[0 150 500 25]);
set(static_women,'String',woman_text);

% Location of display for men
man_1 = uicontrol('Style','text','Position',[0 325 500 25]);
man_2 = uicontrol('Style','text','Position',[0 300 500 25]);

% Location of display for momen
woman_1 = uicontrol('Style','text','Position',[0 125 500 25]);
woman_2 = uicontrol('Style','text','Position',[0 100 500 25]);

% Select two men to swap seats
select_men_ids = randperm(10);
men_number_1 = men(1,select_men_ids(1,1));
men_number_2 = men(1,select_men_ids(1,2));

% Select two women to swap seats
select_women_ids = randperm(10);
women_number_1 = women(1,select_women_ids(1,1));
women_number_2 = women(1,select_women_ids(1,2));

% Display numbers
set(man_1,'String',num2str(men_number_1)); % Displays 3 lines, one number per line
set(man_2,'String',num2str(men_number_2)); % Displays 3 lines, one number per line

% Display numbers
set(woman_1,'String',num2str(women_number_1)); % Displays 3 lines, one number per line
set(woman_2,'String',num2str(women_number_2)); % Displays 3 lines, one number per line

pause(number_of_seconds_between_swaps)

end

Subject: Christmas Gimmick - random numbers

From: Ulrik Nash

Date: 12 Dec, 2012 14:26:08

Message: 3 of 4

"Ulrik Nash" <uwn@sam.sdu.dk> wrote in message <ka4oi3$3hu$1@newscl01ah.mathworks.com>...
> "Ulrik Nash" <uwn@sam.sdu.dk> wrote in message <ka4a8k$gju$1@newscl01ah.mathworks.com>...
> > Hi Everyone,
> >
> > My department's Christmas party is coming up, and I have the duties for seating arrangements. To make people mix and mingle a little more than usual, I wish to create a simple program, which draws two numbers at random from a list of participants, every X minutes. This will prompt the two corresponding participants to swap seats (actually, they will meet at the front of the dining hall, pour a glass of snaps, say cheers, and then swap seats!).
> >
> > My questions is, can this be done using MATLAB? Ideally the numbers should be shown on a Christmas image background.
> >
> > I really appreciate your help/advice.
>
> Okay, so far so good. I would really appreciate if someone could tell me how to implement a background image.
>
> for i = 1:N
> % Display area
> display_area = uicontrol('Style','text','Position',[0 0 500 400]);
>
> % Static text:
> man_text={'Would these MEN please come to the front, propose a toast, and then change seats!'};
> static_men = uicontrol('Style','text','Position',[0 350 500 25]);
> set(static_men,'String',man_text);
>
> woman_text={'Would these WOMEN please come to the front, propose a toast, and then change seats!'};
> static_women = uicontrol('Style','text','Position',[0 150 500 25]);
> set(static_women,'String',woman_text);
>
> % Location of display for men
> man_1 = uicontrol('Style','text','Position',[0 325 500 25]);
> man_2 = uicontrol('Style','text','Position',[0 300 500 25]);
>
> % Location of display for momen
> woman_1 = uicontrol('Style','text','Position',[0 125 500 25]);
> woman_2 = uicontrol('Style','text','Position',[0 100 500 25]);
>
> % Select two men to swap seats
> select_men_ids = randperm(10);
> men_number_1 = men(1,select_men_ids(1,1));
> men_number_2 = men(1,select_men_ids(1,2));
>
> % Select two women to swap seats
> select_women_ids = randperm(10);
> women_number_1 = women(1,select_women_ids(1,1));
> women_number_2 = women(1,select_women_ids(1,2));
>
> % Display numbers
> set(man_1,'String',num2str(men_number_1)); % Displays 3 lines, one number per line
> set(man_2,'String',num2str(men_number_2)); % Displays 3 lines, one number per line
>
> % Display numbers
> set(woman_1,'String',num2str(women_number_1)); % Displays 3 lines, one number per line
> set(woman_2,'String',num2str(women_number_2)); % Displays 3 lines, one number per line
>
> pause(number_of_seconds_between_swaps)
>
> end

No help at hand? I would really appreciate it if someone would demonstrate how to place the background image.

Subject: Christmas Gimmick - random numbers

From: someone

Date: 12 Dec, 2012 21:04:09

Message: 4 of 4

"Ulrik Nash" <uwn@sam.sdu.dk> wrote in message <kaa460$a0d$1@newscl01ah.mathworks.com>...
> "Ulrik Nash" <uwn@sam.sdu.dk> wrote in message <ka4oi3$3hu$1@newscl01ah.mathworks.com>...
> > "Ulrik Nash" <uwn@sam.sdu.dk> wrote in message <ka4a8k$gju$1@newscl01ah.mathworks.com>...
> > > Hi Everyone,
> > >
> > > My department's Christmas party is coming up, and I have the duties for seating arrangements. To make people mix and mingle a little more than usual, I wish to create a simple program, which draws two numbers at random from a list of participants, every X minutes. This will prompt the two corresponding participants to swap seats (actually, they will meet at the front of the dining hall, pour a glass of snaps, say cheers, and then swap seats!).
> > >
> > > My questions is, can this be done using MATLAB? Ideally the numbers should be shown on a Christmas image background.
> > >
> > > I really appreciate your help/advice.
> >
> > Okay, so far so good. I would really appreciate if someone could tell me how to implement a background image.
> >
> > for i = 1:N
> > % Display area
> > display_area = uicontrol('Style','text','Position',[0 0 500 400]);
> >
> > % Static text:
> > man_text={'Would these MEN please come to the front, propose a toast, and then change seats!'};
> > static_men = uicontrol('Style','text','Position',[0 350 500 25]);
> > set(static_men,'String',man_text);
> >
> > woman_text={'Would these WOMEN please come to the front, propose a toast, and then change seats!'};
> > static_women = uicontrol('Style','text','Position',[0 150 500 25]);
> > set(static_women,'String',woman_text);
> >
> > % Location of display for men
> > man_1 = uicontrol('Style','text','Position',[0 325 500 25]);
> > man_2 = uicontrol('Style','text','Position',[0 300 500 25]);
> >
> > % Location of display for momen
> > woman_1 = uicontrol('Style','text','Position',[0 125 500 25]);
> > woman_2 = uicontrol('Style','text','Position',[0 100 500 25]);
> >
> > % Select two men to swap seats
> > select_men_ids = randperm(10);
> > men_number_1 = men(1,select_men_ids(1,1));
> > men_number_2 = men(1,select_men_ids(1,2));
> >
> > % Select two women to swap seats
> > select_women_ids = randperm(10);
> > women_number_1 = women(1,select_women_ids(1,1));
> > women_number_2 = women(1,select_women_ids(1,2));
> >
> > % Display numbers
> > set(man_1,'String',num2str(men_number_1)); % Displays 3 lines, one number per line
> > set(man_2,'String',num2str(men_number_2)); % Displays 3 lines, one number per line
> >
> > % Display numbers
> > set(woman_1,'String',num2str(women_number_1)); % Displays 3 lines, one number per line
> > set(woman_2,'String',num2str(women_number_2)); % Displays 3 lines, one number per line
> >
> > pause(number_of_seconds_between_swaps)
> >
> > end
>
> No help at hand? I would really appreciate it if someone would demonstrate how to place the background image.

Since no one else has answered, I'll take a stab at it.

I tried running your code but I get an error when it gets to the line:
men_number_1 = men(1,select_men_ids(1,1));
(Men is an undefined function - I believe the same will happen for women.)

If I understand what you are asking, I don't believe there is a way to put a background image on a static text uicontrol. Unless there is a "low-level" way to do it in java that I'm not aware of. I believe you can do it with push or toggle buttons using the CData property.

If I understand your code above, there is nothing special about using a static text uicontrol. Why not display your background using the IMAGE command:

doc image

(see Example 2) and use the TITLE command to display the text.
Or display the man/woman numbers on the resulting axes object using the TEXT command:

doc text

Tags for 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