【问题标题】:retrieve values and export to workspace from a radiobutton in a buttongroup从按钮组中的单选按钮检索值并导出到工作区
【发布时间】:2015-05-27 16:09:16
【问题描述】:

我正在尝试修改此 gui http://www.mathworks.com/matlabcentral/fileexchange/20604-3d-slice-viewer,因为我想添加一个功能。这个新功能是评估疾病,我的意思是如果当前查看器上的切片有疾病,用户单击是,否则单击否。每个病人应该做几次。出于学习目的,我使用了 matlab 中的 mri 数据。

问题是我使用指南添加了一个带有两个单选按钮的新框(按钮组)。但我无法从 gui 中获得任何价值。当我只使用 get(eventdata.NewValue, 'Tag') 时,每次单击按钮时,我都可以在命令窗口中看到按钮的值,但我不知道如何保存这些单击。我尝试了以下方法但没有成功:

% --- Executes when selected object is changed in Assess.
function Assess_SelectionChangeFcn(hObject, eventdata, handles)
% hObject    handle to the selected object in EmphyAssess 
% eventdata  structure with the following fields (see UIBUTTONGROUP)
%   EventName: string 'SelectionChanged' (read only)
%   OldValue: handle of the previously selected object or empty if none was selected
%   NewValue: handle of the currently selected object
% handles    structure with handles and user data (see GUIDATA)

switch get(eventdata.NewValue,'Tag')   % Get Tag of selected object
    case '1'
        value = 1; 
        Setappdata(hObject,'result', value); 

      case '2'
          value= 0; 
          Setappdata(hObject,'result', value); 

end

% --- Outputs from this function are returned to the command line.
function varargout = SliceBrowserIsa_OutputFcn(hObject, eventdata, handles)
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure

   varargout{1} = getappdata(hObject,'result');

【问题讨论】:

  • 在图形对象中存储值使用guidata

标签: matlab user-interface matlab-guide


【解决方案1】:

您可以使用guidata(hObject,handles) - look here for more info 更新句柄对象。之后,您应该能够访问该值。

您的问题还提到了导出到工作区 - 您可以使用 assignin('base', 'variable', value) - see here

【讨论】:

  • 嗨@cwissy,我已经按照您在第一个示例中的建议通过使用 guidata(hObject, handles) 修改了我的代码,但我仍然无法在 GUI 之外获取值。我尝试了分配,但没有任何反应。还有其他想法吗?也许问题是我没有很好地使用它,你能为我树立一个榜样吗?谢谢
  • 如果您输入assignin('base','result',value),您应该在工作区中有一个result 变量。你试过调试吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-03-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-04-03
  • 2016-02-08
  • 1970-01-01
相关资源
最近更新 更多