在GUI中存储工作区变量以供其他按钮使用. MATLAB GUI [英] Storing workspace variable in GUI for use by other push buttons. MATLAB GUI
问题描述
我刚刚开始使用GUIDE制作基本的GUI,到目前为止,我有一个按钮可以用来调用我先前编写的名为sortData.m的.m文件
I have just started making a basic GUI with GUIDE, so far I have one push button that I am using to call a .m file I wrote earlier called sortData.m
当在GUI外部运行时,sortData.m会将一个名为合并"的矩阵放入工作区,但是当我在GUI中运行sortData.m时,什么都不会发生.
When run outside of the GUI, sortData.m puts a matrix called "merge" into the workspace, but when I run sortData.m inside the GUI nothing happens.
我需要合并"存储在某个位置,以便我的下一个按钮可以使用它来输出图形...该怎么办?谢谢
I need "merge" to get stored somewhere so that my next push button can use it to output figures... how can this be done? Thanks
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
sortData
推荐答案
-
修改sortData->使其成为函数,方法是将其添加为第一行:
modify sortData-> make it a function by adding this as the first line:
function merge = sortData(..)
function merge = sortData(..)
修改回调:
功能pushbutton1_Callback(hObject,eventdata,handles) 合并= sortData handles.merge =合并 guidata(hObject,handles);
function pushbutton1_Callback(hObject, eventdata, handles) merge = sortData handles.merge = merge guidata(hObject, handles);
随后,在获取handles-struct的任何回调中,您可以使用 handles.merge 检索数据. 查看文档以获取有关数据共享的更多信息,请参见(例如):
later, within any callback that gets the handles-struct, you can retrieve the data with handles.merge. Check the documentation for more about data-sharing, see (for example):
- TMW-newsreader
- TMW: documentation guidata
这篇关于在GUI中存储工作区变量以供其他按钮使用. MATLAB GUI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!