如何在工作区中保存 MATLAB 句柄>
How do you save MATLAB handles in workspace>
我正在编写图像配准代码,我想将固定图像 (handles.imgFixed) 和移动图像 (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);
谢谢 - 我感谢你的时间和建议
- 您可以使用 assignin 在基础工作区中保存一个变量,然后使用 evalin 取回她。
assignin('base', 'imgFixed', handles.imgFixed)
- 将 handles.imgFixed 导出到基础工作区
- 您还可以将 handles.imgFixed 分配给 global variable。通过这种方式,您可以从所有其他功能访问它。
globale imgFixed; imgFixed = handles.imgFixed;
但是我不知道我是否完全理解你的问题。为什么要将这些图像存储在工作区中?传递变量的句柄有什么问题?
我正在编写图像配准代码,我想将固定图像 (handles.imgFixed) 和移动图像 (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);
谢谢 - 我感谢你的时间和建议
- 您可以使用 assignin 在基础工作区中保存一个变量,然后使用 evalin 取回她。
assignin('base', 'imgFixed', handles.imgFixed)
- 将 handles.imgFixed 导出到基础工作区 - 您还可以将 handles.imgFixed 分配给 global variable。通过这种方式,您可以从所有其他功能访问它。
globale imgFixed; imgFixed = handles.imgFixed;
但是我不知道我是否完全理解你的问题。为什么要将这些图像存储在工作区中?传递变量的句柄有什么问题?