Got Questions? Get Answers.
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:
How do I code for placing an unknown number of Checkboxes?

Subject: How do I code for placing an unknown number of Checkboxes?

From: Conrad Andrew

Date: 13 Aug, 2009 21:10:21

Message: 1 of 4

Hi there

I'd like to have a simple GUI where a number of checkboxes are placed programmatically. This number depends on user input so may vary. Let's say that on day 1, M may contain ['A1','A2'] but on day 2, it may have ['A1','A2','A3']. How do I generate a code that will place a number of checkboxes dependent on the size of M?

Thanks very much for any help on this matter

Subject: How do I code for placing an unknown number of Checkboxes?

From: Chaos

Date: 13 Aug, 2009 22:15:24

Message: 2 of 4

"Conrad Andrew" <conrad7@gmx.net> wrote in message <h61vft$b96$1@fred.mathworks.com>...
> Hi there
>
> I'd like to have a simple GUI where a number of checkboxes are placed programmatically. This number depends on user input so may vary. Let's say that on day 1, M may contain ['A1','A2'] but on day 2, it may have ['A1','A2','A3']. How do I generate a code that will place a number of checkboxes dependent on the size of M?
>
> Thanks very much for any help on this matter

matlab/java has no ability to create code like this, use Perl instead.

Subject: How do I code for placing an unknown number of Checkboxes?

From: Shaun

Date: 13 Aug, 2009 22:40:20

Message: 3 of 4

"Conrad Andrew" <conrad7@gmx.net> wrote in message <h61vft$b96$1@fred.mathworks.com>...
> Hi there
>
> I'd like to have a simple GUI where a number of checkboxes are placed programmatically. This number depends on user input so may vary. Let's say that on day 1, M may contain ['A1','A2'] but on day 2, it may have ['A1','A2','A3']. How do I generate a code that will place a number of checkboxes dependent on the size of M?
>
> Thanks very much for any help on this matter


numChk = inputdlg('Number of Check Boxes');
numChk = str2double(numChk);
uh = zeros(1,numChk);
for i = 1:numChk
   uh(i) = uicontrol('Style','check');
   if i > 1
      pos = get(uh(i-1),'Position');
      pos(2) = pos(2)+20;
      set(uh(i),'Position',pos)
   end
end


hth
Shaun

Subject: How do I code for placing an unknown number of Checkboxes?

From: Conrad Andrew

Date: 14 Aug, 2009 17:17:07

Message: 4 of 4

"Shaun" <s@s.com> wrote in message <h624oj$6ms$1@fred.mathworks.com>...
> "Conrad Andrew" <conrad7@gmx.net> wrote in message <h61vft$b96$1@fred.mathworks.com>...
> > Hi there
> >
> > I'd like to have a simple GUI where a number of checkboxes are placed programmatically. This number depends on user input so may vary. Let's say that on day 1, M may contain ['A1','A2'] but on day 2, it may have ['A1','A2','A3']. How do I generate a code that will place a number of checkboxes dependent on the size of M?
> >
> > Thanks very much for any help on this matter
>
>
> numChk = inputdlg('Number of Check Boxes');
> numChk = str2double(numChk);
> uh = zeros(1,numChk);
> for i = 1:numChk
> uh(i) = uicontrol('Style','check');
> if i > 1
> pos = get(uh(i-1),'Position');
> pos(2) = pos(2)+20;
> set(uh(i),'Position',pos)
> end
> end
>
>
> hth
> Shaun

This is good stuff Shaun. Exactly what I needed. Thanks a lot!

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