Data handling in GUI

Hello, I have a GUI and want to get the Data from the push button callback into the workspace to use it for further steps in my programm. Best regards Nico Subic

Answers (1)

Jan
Jan on 9 Aug 2017
Edited: Jan on 9 Aug 2017
It is a bad idea in general to create data in the base workspace. Such a remote controlled creating of variables is hard to debug and suffers from the same problems as global variables (a short search in the net or the forum will reveal them).
But it works. If you post the relevant part of the code, posting an answer would require less creativity, but I try it:
function ButtonCallback(jObject, EventData, handles)
handles = guidata(hObject);
Data = handles.myData;
assignin('Base', 'DataFromGui', Data); % Working, but not smart
end
Again: I never create variables in the base workspace to avoid any possibility to overwrite other values. I keep the values inside the GUI and start the function from there by a callback. Or I add a function to the GUI, which let it reply the data, such that they can be requested from another function. Think twice if writing to the base workspace is really useful in a long term of view.

Categories

Find more on App Building in Help Center and File Exchange

Tags

Asked:

on 9 Aug 2017

Edited:

Jan
on 9 Aug 2017

Community Treasure Hunt

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

Start Hunting!