Skip to Main Content Skip to Search
Login
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

Thread Subject: GUI and Integration with own code!

Subject: GUI and Integration with own code!

From: Colin

Date: 25 Jun, 2008 16:14:02

Message: 1 of 6

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

Subject: GUI and Integration with own code!

From: Jomar Bueyes

Date: 25 Jun, 2008 17:02:57

Message: 2 of 6

On Jun 25, 11:14 am, "Colin " <coup...@gmail.com> wrote:
> 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,

You could get the input arguments using 'inputdlg' instead of
prompting for them. With inputdlg you can change the value(s) you want
to change and not re-enter all the arguments.

HTH

Jomar

Subject: GUI and Integration with own code!

From: Yuri Geshelin

Date: 25 Jun, 2008 19:40:19

Message: 3 of 6

"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

Subject: GUI and Integration with own code!

From: Colin

Date: 1 Jul, 2008 10:22:05

Message: 4 of 6

"Yuri Geshelin" <geshelin@hotmail.com> wrote in message
<g3u6v3$f4k$1@fred.mathworks.com>...
> "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
>

Hey - this looks great!

Just a couple of quick questions:

1. Would this just go at the start of the existing code? or
do I need to do seomthing more to add it in?

Thanks again for all your help!

All I have to do is modify this to change 8 other values!

TiA

Colin

Subject: GUI and Integration with own code!

From: Colin

Date: 1 Jul, 2008 13:45:06

Message: 5 of 6

Also, another quick question, How are you drawing the box
for the Tau parameter - i have edited the code but can't
seem to be able to draw a new box

Subject: GUI and Integration with own code!

From: Yuri Geshelin

Date: 4 Jul, 2008 14:38:01

Message: 6 of 6

"Colin " <couperc@gmail.com> wrote in message <g4dcd2$s26
$1@fred.mathworks.com>...
> Also, another quick question, How are you drawing the box
> for the Tau parameter - i have edited the code but can't
> seem to be able to draw a new box

Hi Colin,

To answer your questions,

1) This does not have to be at the very top of the existing
code. Just to get organized, put the internal function
do_redraw at the bottom of the code.

2) I did not explicitly draw the box for the Tau parameter.
The box is there because you use the 'edit' style for this
uicontrol handle. To draw another box, define another
handle in the same way.

Yuri

Tags for this Thread

Everyone's Tags:

gui

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

Tag Activity for This Thread
Tag Applied By Date/Time
gui Colin 1 Jul, 2008 08:17:17
rssFeed for this Thread

envelope graphic E-mail this page to a colleague

Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.
Related Topics