For Programmers: Free Programming Magazines  


Home > Archive > Matlab > July 2006 > Dynmaic Edit Boxes and Callbacks









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Dynmaic Edit Boxes and Callbacks
Cihan Baran

2006-07-26, 7:05 pm

Hello there,

I am programming a data viewer for Stanford Starlab, VLF group, using
MATLAB. One of the feauters they like is the ability to allow the user
to specify an arbitrary frequency response filter. The user will
specify 200 passband magnitudes for every 250Hz between 0 and 50kHz.
The software will create the specified filter, filter the data and
output a spectrogram.

Even though I know all the filter implementation details, I am having
trouble coming up with a convenient way to get 200 inputs from the
user. I can sequentially get this but that's very "user-unfriendly".

My idea is to create 200 edit text boxes for each passband (with static
texts that specifiy the range next to them) and let the user enter them
one by one.

I don't really know how to do this. I could create dynamically 200 edit
boxes using a for loop but how would I manage 200 different callback
functions? Is there a way to define 200 callback functions dynamically
as well?

Thanks for any and all input,
Cihan

us

2006-07-26, 7:05 pm

Cihan Baran:
<SNIP trying to keep track of zillions of edit boxes...

one of the solutions is outlined below

% create the boxes
[x,y]=meshgrid([.1,.4]);
uh=[];
for i=1:numel(x)
uh(i)=uicontrol('units','normalized',...
'position',[x(i),y(i),.2,.2],...
'userdata',i,...
'string',num2str(i,'box#%-1d'));
end
% ...and a re-usable callback routine
com=['sprintf(''my ID %1d:%s'','...
'get(gcbo,''userdata''),'...
'get(gcbo,''string''))'];
% ...for all boxes
set(uh,'callback',com);
% now, click any box and see what happens

after this prelim example you'd get real:
create a true callback function, eg,

function mycb(h,e)
ud=get(h,'userdata');
us=get(h,'string');
% followed by some engine based on the entries
return;

in your main function you'd do this
set(uh,'callback',@mycb)

just a few pointers
us
Cihan Baran

2006-07-31, 7:17 pm

Thank you...

That was really helpful.

Best,
Cihan

us wrote:
> Cihan Baran:
> <SNIP trying to keep track of zillions of edit boxes...
>
> one of the solutions is outlined below
>
> % create the boxes
> [x,y]=meshgrid([.1,.4]);
> uh=[];
> for i=1:numel(x)
> uh(i)=uicontrol('units','normalized',...
> 'position',[x(i),y(i),.2,.2],...
> 'userdata',i,...
> 'string',num2str(i,'box#%-1d'));
> end
> % ...and a re-usable callback routine
> com=['sprintf(''my ID %1d:%s'','...
> 'get(gcbo,''userdata''),'...
> 'get(gcbo,''string''))'];
> % ...for all boxes
> set(uh,'callback',com);
> % now, click any box and see what happens
>
> after this prelim example you'd get real:
> create a true callback function, eg,
>
> function mycb(h,e)
> ud=get(h,'userdata');
> us=get(h,'string');
> % followed by some engine based on the entries
> return;
>
> in your main function you'd do this
> set(uh,'callback',@mycb)
>
> just a few pointers
> us


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com