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:
automatically update editbox of one GUI with contents entered in 2nd GUI

Subject: automatically update editbox of one GUI with contents entered in 2nd GUI

From: Alex

Date: 12 Apr, 2012 01:32:31

Message: 1 of 4

I have a GUI that runs a pretty intense data analysis on videos. For a new type of data I need to run, I have modified my original GUI to launch a 2nd GUI that lets me preview a portion of the data. After previewing the the data, I can also input initial conditions into the 2nd GUI, and import them into my main GUI with a push button (via setappdata and getappdata).

Part of the preview (2nd GUI) is to help me select a single, specific frame of the video to analyze, and cut out parts of the video's frames that do not contain useful data, and would only take up cpu/ram for no real need. When I identify the frame I would like to use, I enter it in an editbox, which is (successfully) passed/imported to the code of the main GUI.

There is another editbox in the main GUI that serves the same function that is being kept for the sake of the old data analysis method (as I will be needing it also).

My question is how do I get the frame number I entered in the 2nd GUI to appear in the corresponding editbox of the main GUI when I import the variables?

Short version:
          I want to update the contents of an editbox of one GUI with the contents entered into the editbox of a 2nd GUI.

something like:
gaussianFrame = str2num(get(handles.GUI_2_editbox,'string')); %get frame number entered in 2nd gui

set(handles.GUI_1_editbox, 'string', gaussianFrame); %set string in 1st gui editbox to gaussianFrame

Subject: automatically update editbox of one GUI with contents entered in 2nd GUI

From: Matthew

Date: 12 Apr, 2012 01:53:33

Message: 2 of 4

you can use guidata:
http://www.mathworks.com/help/techdoc/creating_guis/f13-998449.html

However, the way I've approached this problem in the past is to write all of my processing code into a handle object. The GUI takes the handle to the object and registers listeners on any properties and events that it cares about with proper callbacks to deal with the change in data. So instead of having to write one GUI to talk to the other, you just write each GUI to update the base object and update itself when something it cares about in the base object changes.

"Alex " <blue.harvest.83@gmail.com> wrote in message <jm5bbf$82n$1@newscl01ah.mathworks.com>...
> I have a GUI that runs a pretty intense data analysis on videos. For a new type of data I need to run, I have modified my original GUI to launch a 2nd GUI that lets me preview a portion of the data. After previewing the the data, I can also input initial conditions into the 2nd GUI, and import them into my main GUI with a push button (via setappdata and getappdata).
>
> Part of the preview (2nd GUI) is to help me select a single, specific frame of the video to analyze, and cut out parts of the video's frames that do not contain useful data, and would only take up cpu/ram for no real need. When I identify the frame I would like to use, I enter it in an editbox, which is (successfully) passed/imported to the code of the main GUI.
>
> There is another editbox in the main GUI that serves the same function that is being kept for the sake of the old data analysis method (as I will be needing it also).
>
> My question is how do I get the frame number I entered in the 2nd GUI to appear in the corresponding editbox of the main GUI when I import the variables?
>
> Short version:
> I want to update the contents of an editbox of one GUI with the contents entered into the editbox of a 2nd GUI.
>
> something like:
> gaussianFrame = str2num(get(handles.GUI_2_editbox,'string')); %get frame number entered in 2nd gui
>
> set(handles.GUI_1_editbox, 'string', gaussianFrame); %set string in 1st gui editbox to gaussianFrame

Subject: automatically update editbox of one GUI with contents entered in 2nd GUI

From: Alex

Date: 12 Apr, 2012 02:09:29

Message: 3 of 4

Thanks Matthew, I think your suggestion about listeners is what I am looking for, however I am not familiar with listeners, and "help listener" doesn't return any results . Could you give me a brief example of code that would utilize listeners with respect to my problem?
Thanks

"Matthew" wrote in message <jm5cit$cdg$1@newscl01ah.mathworks.com>...
> you can use guidata:
> http://www.mathworks.com/help/techdoc/creating_guis/f13-998449.html
>
> However, the way I've approached this problem in the past is to write all of my processing code into a handle object. The GUI takes the handle to the object and registers listeners on any properties and events that it cares about with proper callbacks to deal with the change in data. So instead of having to write one GUI to talk to the other, you just write each GUI to update the base object and update itself when something it cares about in the base object changes.

Subject: automatically update editbox of one GUI with contents entered in 2nd GUI

From: Matthew

Date: 12 Apr, 2012 03:04:26

Message: 4 of 4

Sure,
This is the documentation you want to look at

http://www.mathworks.com/help/techdoc/matlab_oop/brb6gnc.html

The basic idea is that you create a handle object with properties with 'SetObservable'
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% object:
classdef test_obj < handle
   
   properties (SetObservable, AbortSet)
      a;
      b;
      c;
   end

   events
     overflow;
   end

  methods
     function set.a(this,value)
            if value > 10
               notify(this,'overflow');
               fprintf('a cannot exceed 10');
            else
                this.a = value;
            end
     end
  end

end

%%%%%%%%%%%%%%%%%%%%%

now create an instance of the object:

%%%%%

test = test_obj;

%%%%%%

Now you can register listeners

%%%%%%%%%%%%%%%%%
% you can listen to an event, which you throw manually in the code:
%Whenever the overflow event is thrown, the callback is executed. The callback is
%always fed two parameters, the object sending the notification and event data

list{1} = test.addlistener('overflow',@(obj,event)fprintf('OVERFLOW\n'));

% you can also listen to individual properties in the same way. When the property
% changes, the callback is called. You can call use "PreSet", "PostSet", "PreGet' and
% "PostGet" to decide when the callback is triggered.

list{2} = t.addlistener('b','PostSet',@(obj,event)fprintf('B was just set\n'));

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

In a gui, I register my listeners like this:

handles.listeners{1} = handles.object.addlistener('property','PostSet',@(obj,event)updatedisplay(handles));

This causes the updatedisplay callback (in the gui) to be called every time object.property is updated.

Then in your GUI, all you have to do is directly update the object and let the listeners do their thing. Since the object is a handle class, you can update any "copy" of it as all copies are just references to the same object. This lets you manipulate the object (and thus any attached GUIs) from a script or command line as well, and the GUI's will auto update to reflect the changes.

Just make sure you include a close function in your GUI that deletes the listeners or you will wind up with some odd "object deleted" errors if the listeners become orphaned.

Hope this helps.


"Alex " <blue.harvest.83@gmail.com> wrote in message <jm5dgp$fg1$1@newscl01ah.mathworks.com>...
> Thanks Matthew, I think your suggestion about listeners is what I am looking for, however I am not familiar with listeners, and "help listener" doesn't return any results . Could you give me a brief example of code that would utilize listeners with respect to my problem?
> Thanks
>
> "Matthew" wrote in message <jm5cit$cdg$1@newscl01ah.mathworks.com>...
> > you can use guidata:
> > http://www.mathworks.com/help/techdoc/creating_guis/f13-998449.html
> >
> > However, the way I've approached this problem in the past is to write all of my processing code into a handle object. The GUI takes the handle to the object and registers listeners on any properties and events that it cares about with proper callbacks to deal with the change in data. So instead of having to write one GUI to talk to the other, you just write each GUI to update the base object and update itself when something it cares about in the base object changes.

Tags for 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