|
"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
|