【问题标题】:How do you save MATLAB handles in workspace>如何在工作区中保存 MATLAB 句柄>
【发布时间】:2015-07-29 19:34:27
【问题描述】:

我正在编写图像注册代码,我想将固定图像 (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);

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

【问题讨论】:

    标签: matlab matlab-guide


    【解决方案1】:
    1. 您可以使用 assignin 将变量保存在基础工作区中,然后使用 evalin 将其取回。 assignin('base', 'imgFixed', handles.imgFixed) - 将handles.imgFixed 导出到基础工作区
    2. 您还可以将handles.imgFixed 分配给global variable。通过这种方式,您可以从其他所有功能访问它。 globale imgFixed; imgFixed = handles.imgFixed;

    但我不知道我是否完全理解你的问题。为什么要将这些图像存储在工作区中?传递变量的句柄有什么问题?

    【讨论】:

    • 对我的回答不满意?
    猜你喜欢
    • 2014-10-12
    • 1970-01-01
    • 1970-01-01
    • 2012-09-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-25
    • 1970-01-01
    相关资源
    最近更新 更多