|
"Colin " <couperc@gmail.com> wrote in message
<g3tqsa$c7p$1@fred.mathworks.com>...
> Hi
> I currently have a function written by another researcher
> which I am trying to add a GUI to. Currently all the
> parameters it requires are entered via command line using
> something like this:
> tau=input('Enter value of tau parameter: ');
>
> I have about 8 or nine parameters to enter each time and
so
> I am trying to find a way to enter all teh parameters once
> and then change them according to my need(if that makes
> sense). What i am trying to do is update the end result(a
> graph) in real time, basically whenever I change a
parameter
> i want the graph to update auto matically instead of me
> having to enter the 9 parameters again vis the command
line.
>
> I understand in principle how the GUI works and how to
> create them (easy enough using GUIDE) but I am at a loss
as
> to how i can use the current function and integrate a gui
> into it so i don;t have to re-write the code from scratch
> (something I would be unable to do)
> Thanks in advance
> Colin
Hi Colin,
Jomar's suggestion is fine, but this is not GUI.
To develop a GUI, use function uicontrol. In your case, I
would use either 'slider' or 'edit' style. The latter is
simpler, let's consider the following nested-function
approach (function refresh_plot)
%%%%%%%%%%%%%%%%%% TOP OF REFRESH_PLOT %%%%%%%%%%%%%
function refresh_plot
close all
figure(1), set(1,'position',[170 660 560 420])
taubox_handle = uicontrol;
set(taubox_handle,'style','edit','position',[50 50 50
20])
annotation(1,'textbox','Position',[0.019 0.09703 0.07202
0.0746],...
'String',{'TAU'},'linest','n');
Redraw_button_handle = uicontrol;
set(Redraw_button_handle,'style','pushbutton','position',
[150 50 80 40],'string','redraw','callback',@do_redraw)
function do_redraw(dummy1,dummy2)
tau_text = get(taubox_handle,'string');
tau_value = sscanf(tau_text,'%f');
x = -3:0.01:3;
y = tau_value*x.^2;
figure(2), set(2,'position',[870 660 560 420])
plot(x,y)
end
end
%%%%%%%%%%%%%% BOTTOM OF REFRESH_PLOT %%%%%%%%%%%%%%%%%
First of all, try it out and see if it works. You should be
able to change the value in the box, then hit the 'redraw'
button and see the plot changing.
The core of the internal function, do_redraw, are these two
lines:
x = -3:0.01:3;
y = tau_value*x.^2;
Let's suppose that this is what your colleague has written
up. In addition, your colleague has used input('...'), but
this is now replaced with
(a) the external function refresh_plot
(b) the mechanism, by which that external function passes
the data to your colleague's function do_redraw. It gets
transferred via handle to the TAU-box and handle to the
internal function.
HTH
Yuri
|