From: Isaac on
Hi all :-)
i have to make a gui with a lot of uicontrol like :

ui1 = uicontrol(f,'Style','edit','String','','Units', 'normalized','Position',[0.9 0.97 0.07 0.03]);
ui2 = uicontrol(f,'Style','edit','String','','Units', 'normalized','Position',[0.9 0.94 0.07 0.03]);
ui3 = uicontrol(f,'Style','edit','String','','Units', 'normalized','Position',[0.9 0.91 0.07 0.03]);

etc...

is there a way to create them with a cycle for?

something that should sound like

for j=1:n

ui "j" =uicontrol(f,'Style','edit','String','','Units', 'normalized','Position',[0.9 1-j*0.03 0.07 0.03]);

end


thanks a lot :)
From: Donn Shull on
"Isaac " <asimov4000(a)hotmail.com> wrote in message <htlths$go1$1(a)fred.mathworks.com>...
> Hi all :-)
> i have to make a gui with a lot of uicontrol like :
>
> ui1 = uicontrol(f,'Style','edit','String','','Units', 'normalized','Position',[0.9 0.97 0.07 0.03]);
> ui2 = uicontrol(f,'Style','edit','String','','Units', 'normalized','Position',[0.9 0.94 0.07 0.03]);
> ui3 = uicontrol(f,'Style','edit','String','','Units', 'normalized','Position',[0.9 0.91 0.07 0.03]);
>
> etc...
>
> is there a way to create them with a cycle for?
>
> something that should sound like
>
> for j=1:n
>
> ui "j" =uicontrol(f,'Style','edit','String','','Units', 'normalized','Position',[0.9 1-j*0.03 0.07 0.03]);
>
> end
>
>
> thanks a lot :)

There is a way to do what you have asked however you are better off not knowing it. It is really bad programming practice. Instead you should think about makind your ui's a ui handle vector then your code vould be written as:

ui = zeros(1, n);

for j=1:n

ui(n) =uicontrol(f,'Style','edit','String','','Units', 'normalized','Position',[0.9 1-j*0.03 0.07 0.03]);

end

An alternative which is also bad programming practice but may be necessary if for some reason n is unknown is:

ui = [];

for j=1:n

ui(end+1) =uicontrol(f,'Style','edit','String','','Units', 'normalized','Position',[0.9 1-j*0.03 0.07 0.03]);

end

The reason this is bad is because ui changes size on each iteration through the loop so there are memory management and performance issues created by this code.

good luck,

Donn
From: Isaac on
thanks!!!!!!!