MATLAB:在两个GUI

时间:2015-08-11 14:51:58

标签: matlab matlab-guide handles

我有两个带有图标标签mainWindow和annotatorWindow的GUI。我想在两个窗口之间传递数据。当我将数据从mainWindow复制到annotatorWindow(请参阅copyData_Callback)时,它完美无缺。但是当我想将数据写回mainWindow(参见saveData_Callback)时,我得到错误“Matrix indices must must full double”。我不完全确定这甚至意味着什么,任何帮助都表示赞赏。感兴趣的代码如下。

CALLBACKS UNDER annotatorWindow



% --- Executes on button press in copyData.
function copyData_Callback(hObject, eventdata, handles)
% hObject    handle to copyData (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

h = findobj('Tag', 'mainWindow'); 

if ~isempty(h)
    pData = guidata(h)
    handles.UserData = pData.UserData 
end 

guidata(hObject, handles); 

return

% --- Executes on button press in saveData.
function saveData_Callback(hObject, eventdata, handles)
% hObject    handle to saveData (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

h = findobj('Tag', 'mainWindow'); 

if ~isempty(h) 
    guidata(h).UserData = handles.UserData 
end

guidata(hObject, handles); 

return

1 个答案:

答案 0 :(得分:0)

想出来!要在两个GUI之间传递数据,您只能从GUI中提取数据。您永远不能从另一个GUI将数据写入GUI。我在mainWindow中创建了一个名为saveData的函数(见下文)。然后,我从saveData调用了annotatorWindow函数,允许我来回传递数据。

mainWindow

function saveData(hObject, handles)

h = findobj('Tag', 'annotatorWindow'); 

if ~isempty(h)
    aData = guidata(h) 
    handles.UserData = aData.UserData
end

guidata(hObject, handles); 


return 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
annotatorWindow

% --- Executes on button press in saveData.
function saveData_Callback(hObject, eventdata, handles)
% hObject    handle to saveData (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

h = findobj('Tag', 'mainWindow'); 

annotatorGUI('saveData', h, guidata(h));

return