Loers Antario
Loers Antario

Reputation: 1651

Retrive data from gui object while executing a script file

I have a simple gui where the user enters some data and executes a script file afterwards. I want to extract the data entered in the text boxes and tables from the gui. How can I perform that ?

Note: the gui is just used to enter data. That is the user has to call the script file from the workspace after entering the data in the gui.

Upvotes: 0

Views: 59

Answers (2)

il_raffa
il_raffa

Reputation: 5175

To extract data from a uicontrol you can use wwhat is called "dot notation":

h=uicontrol('styile','edit');
text=h.string;

(more uicontrol parameters should be defined)

As alternative, you can use the "old style" function get

h=uicontrol('styile','edit');
text=get(h,'string')

About the user required to manually run the script, you can also "automate" it by assigning the script to the callback property of a uicontrol (e. g. to a pushbutton)

h=uicontrol('style','pushbutton','callback','my_script')

the my_scriptm-file will be execute when the user presses the pushbutton.

Hope this helps.

Upvotes: 1

andrvibo
andrvibo

Reputation: 151

Right-click the uicontrol in the gui and select View Callbacks->Callback.

If your uicontrol is an editbox these lines would set the variable myData in the base workspace to the data entered in the editbox if you add these lines to the callback function:

assignin('base','myData',get(hObject,'String'));

If your uicontrol is something else than an editbox the 'String' might be 'Value'. Right click the uicontrol and select the Property Inspector to find the attribute of interest.

Upvotes: 0

Related Questions