我刚刚开始用GUIDE制作一个基本的GUI,到目前为止,我有一个按钮,我用来调用我之前写的.m文件,名为sortData.m
当在GUI之外运行时,sortData.m会放置一个名为" merge"的矩阵。进入工作区,但是当我在GUI中运行sortData.m时没有任何反应。
我需要"合并"存储在某处,以便我的下一个按钮可以用它来输出数字......怎么能这样做?感谢
% --- 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
答案 0 :(得分:0)
您可以将结果存储在GUI
内以供日后使用,即:
% --- 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)
handles.mydata = sortData;
guidata(hObject, handles);
或者您可以在需要时从工作区检索数据,即:
my_merge = evalin('base', 'merge');
% do anything with my_merge here
% note that nothing affects matrix merge in workspace
答案 1 :(得分:0)
修改sortData->通过将其添加为第一行来使其成为一个函数:
function merge = sortData(..)
修改回调:
function pushbutton1_Callback(hObject,eventdata,handles) merge = sortData handles.merge = merge guidata(hObject,handles);
稍后,在获取handle-struct的任何回调中,您可以使用 handles.merge 检索数据。 有关数据共享的更多信息,请查看文档,请参阅(例如):