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

回答 (1 件)

Jan
Jan 2017 年 8 月 9 日
編集済み: Jan 2017 年 8 月 9 日

0 投票

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.

カテゴリ

ヘルプ センター および File Exchange で App Building についてさらに検索

タグ

質問済み:

2017 年 8 月 9 日

編集済み:

Jan
2017 年 8 月 9 日

Community Treasure Hunt

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

Start Hunting!

Translated by