Matlab GUI- Workspace to GUI display

I want to put the workspace variable value(s) from Matlab Workspace into the GUI to display in the text area highlighted yellow. My simulation happens with a m-file working online tuning and stored the value in the workspace. After each complete final value is stored in the workspace, i would like to use a pushbutton name (show output) and display it in the text box.
function output_Callback(hObject, eventdata, handles)
% hObject handle to output (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global Kp
Kp=Kp
set(handles.output,'String',num2str(Kp))
I have even tried using global declaration but no success. My objective is to use the PUSHBUTTON and get the value display for all the parameters from the workspace which is available.. please help. Thank you
Nitesh

Réponses (2)

Adam
Adam le 4 Nov 2015
Modifié(e) : Adam le 4 Nov 2015
Put them all in a struct and pass it in as an argument to the GUI.
Then initialise the ui components from that. You will have to launch the GUI from command line (or a script or function) though to do this as e.g.
MyGUI( someStruct );
You could pass them all in as individual arguments if you prefer, but that seems a little excessive.

4 commentaires

Nitesh
Nitesh le 4 Nov 2015
Modifié(e) : Nitesh le 4 Nov 2015
Thank Adam, Please can you be more clear. My gui name is 'final' and i would like to use pushbutton tag-output to display on text-Kp. I need to only use the callback function.
I dont understand your command. Please help me again.
I skimmed a little too fast over your first paragraph. I assume you mean you have the UI open and then run the m-file.
If you want your GUI to be linked to some data then you should run the m-file from inside the GUI to store its results in the GUI ideally rather than relying on pulling variables in from the workspace.
If the m-file is run from the GUI then you can store the results in a struct (e.g. 'results' ) attached to the handles structure so that in your callback you can just do something like
set( hObject, 'String', handles.results.Kp )
This would require you to launch your script from the GUI too, but if the GUI is to show the results it would seem to make sense for it to launch the algorithm and show the results.
Hi Adam,
I still cannot display those values in the text box. The m-file is ran from the gui pushbutton and values are stored in the workspace. however, i have used
assignin('base','Kp',Kp)
to save it in the workspace from the gui function file. Can i use this command somehow??
If you instead do something like
handles.results.Kp = Kp;
guidata( hObject, handles )
after you run the algorithm from the GUI then you can then use the syntax above. I have never used assignin nor seen any obvious reason why it would be used in general. If you are working within a GUI keep everything in the GUI rather than dumping things to the base workspace.

Connectez-vous pour commenter.

Arunkumar Muthukumaran
Arunkumar Muthukumaran le 19 Déc 2015

0 votes

You can pass the variable Kp to a function (say MATLAB function) and update GUI handles with the value. This lets you to have the updated value in GUI after each timestep.

Catégories

En savoir plus sur Interactive Control and Callbacks dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by