如何在工作区中保存MATLAB句柄>

时间:2015-07-28 21:15:53

标签: matlab matlab-guide

我正在为图像注册编写代码,我想保存固定的Image(handles.imgFixed)并将Image(handles.imgMoving)移动到MATLAB工作区。这样我计划使用evalin将这些变量带回MATLAB GUI进行进一步分析。这是我的GUI代码:

function uploadFixed_Callback(hObject, ~ , handles)
% hObject    handle to uploadFixed (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
[filename, pathname] = uigetfile({'*.gif; *.png; *.jpg; *.tif', 'Image Files(*.gif,*.png,*.jpg,*.tif)';'*', 'All files'}, 'File Selector'); 
set(handles.output,'CurrentAxes',handles.imgFixed);
handles.fixPath = strcat(pathname,filename);
hold off;
imshow(handles.fixPath);
hold on;
set( get(handles.imgFixed,'Children'),'ButtonDownFcn', {@imgFixed_ButtonDownFcn,handles});
set( get(handles.imgMoving,'Children'), 'ButtonDownFcn', {@imgMoving_ButtonDownFcn,handles}); 
guidata(hObject,handles);

% --- Executes on button press in uploadMoved.
function uploadMoved_Callback(hObject, eventdata, handles)
% hObject    handle to uploadMoved (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
[filename,pathname] = uigetfile({'*.gif; *.png; *.jpg; *.tif', 'Image Files (*.gif,*.png,*.jpg,*.tif'; '*', 'All Files'}, 'File Selector');
set(handles.output, 'CurrentAxes', handles.imgMoving);
handles.movePath = strcat(pathname,filename);
hold off;
imshow(handles.movePath);
hold on;
set( get(handles.imgFixed,'Children'), 'ButtonDownFcn', {@imgFixed_ButtonDownFcn,handles});
set( get(handles.imgMoving,'Children'), 'ButtonDownFcn', {@imgMoving_ButtonDownFcn,handles});
guidata(hObject,handles);

% --- Executes on mouse press over axes background.
function imgFixed_ButtonDownFcn(hObject, eventdata, handles)
% hObject    handle to imgFixed (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
set(handles.output, 'CurrentAxes', handles.imgFixed);
imshow(handles.imgFixed);

% --- Executes on mouse press over axes background.
function imgMoving_ButtonDownFcn(hObject, eventdata, handles)
% hObject    handle to imgMoving (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
set(handles.output, 'CurrentAxes', handles.imgMoving);
imshow(handles.imgMoving);

谢谢 - 感谢您的时间和建议

1 个答案:

答案 0 :(得分:0)

  1. 您可以使用assignin将变量保存在基本工作区中,然后使用evalin将其恢复。 assignin('base', 'imgFixed', handles.imgFixed) - 导出handle.imgFixed到基础工作区
  2. 您还可以将handles.imgFixed分配给global variable。通过这种方式,您可以从其他所有功能访问它。 globale imgFixed; imgFixed = handles.imgFixed;
  3. 但我不知道我是否完全理解你的问题。为什么要将这些图像存储在工作区中?传递变量的句柄有什么问题?