Thread Subject: How to read values from m-file?

Subject: How to read values from m-file?

From: didka didka

Date: 24 Jun, 2009 08:45:03

Message: 1 of 2

I need help about a GUI application. I have an application which works. I must get some values from this GUI and use them in other GUI application – read them from the m-file, load in the new one and use them in a formula to calculate some new values. With which command I must do this?

Subject: How to read values from m-file?

From: Samuel Dorrell

Date: 1 Jul, 2009 10:16:02

Message: 2 of 2

"didka didka" <didka_viva@abv.bg> wrote in message <h1sp2f$kas$1@fred.mathworks.com>...
> I need help about a GUI application. I have an application which works. I must get some values from this GUI and use them in other GUI application – read them from the m-file, load in the new one and use them in a formula to calculate some new values. With which command I must do this?

I think I understand the problem. You have 2 GUI's, 1 which is currently running and another which you want to interogate the other for some value. I don't think you can get matlab to 'read them from the m-file' but instead you could read your values from the gui object...

I created a gui object 'convert' by using the command 'guide' and selecting the matlab example gui which converts from density and volume to mass (and saving it as 'convert'). Create the GUI object and a handle to it by typing "h_gui = convert" on the command line.

Say I want to extract the value 'Density' from my GUI object. I could do it as so:
% a list of objects that are contained within h_gui
h_child = get(h_gui,'Children');
% show the tags of these objects
h_child_tag = get(h_child,'tag')
% get the child object with tag 'uipanel1'
h_child_ind = strmatch('uipanel1',h_child_tag);
h_child = h_child(h_child_ind);
% Now look in the uipanel1 object for a child with tag 'density'
h_child_child = get(h_child,'Children');
h_child_child_tag = get(h_child_child,'tag')
h_child_child_ind = strmatch('density',h_child_child_tag)
h_child_child = h_child_child(h_child_child_ind);
% Found it! Now we can get the value of the density (which is stored in the 'string' field in this example)
density_value = str2num(get(h_child_child,'String'))

However. If you want to store random data in your GUI you could save it into the user data field of your GUI:
my_data = struct('name','Sam','data',[1,2,3;4,5,6;7,8,9]);
set(h_gui,'UserData',my_data);

and retrieve it later (as long as the GUI object still exists! The data is lost when the GUI is destroyed):
mydata = gt(h_gui,'UserData');

Hope this helps
Sam

Tags for this Thread

Everyone's Tags:

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 Sprinceana 24 Jun, 2009 06:04:23
read values Sprinceana 24 Jun, 2009 06:04:23
mfile Sprinceana 24 Jun, 2009 06:04:23
rssFeed for this Thread

Contact us at files@mathworks.com