retrieve values and export to workspace from a radiobutton in a buttongroup

조회 수: 3 (최근 30일)
Isabel
Isabel 2015년 5월 26일
댓글: Ashish Gudla 2015년 5월 27일
Hi,
I'm trying to modify this gui http://www.mathworks.com/matlabcentral/fileexchange/20604-3d-slice-viewer because I'd like to add a feature. This new feature is to assess diseases, I mean if the slice that is currently on the viewer has disease the user click yes, otherwise click no. And this should be done several time per patient. For this learning purposes I'm using mri data from matlab.
The issue is that I added a new box (buttongroup) with two radiobutton by using guide. But I can't get any value out of the gui. When I only use get(eventdata.NewValue, 'Tag'), everytime that I click in the buttons I can see in the command window the value of the button, but I don't know how to save these clicks. I have tried without success the follow:
% --- 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');

답변 (1개)

Ashish Gudla
Ashish Gudla 2015년 5월 27일
편집: Ashish Gudla 2015년 5월 27일
You are using the correct function get(eventdata.NewValue,'Tag') to read the tag of the button clicked. However when you want to store the data, you are using 'setappdata' with hObject, which in this function would point to the radio button that was clicked.
To save the data that can be accessed across the entire application, store the initial figure object in a global variable, and use that with 'setappdata'.
You can refer to the sample code from this page where the object handles are stored in 'handles' structure and then used.
  댓글 수: 2
Isabel
Isabel 2015년 5월 27일
Hi Ashish,
I modified the code and I wrote like setappdata(handles.radiobutton3,'result', value); but still I have the problem that I can't get outside how many times a user click the first button and how many times the user click the second button.
Do you have any idea how I can do that? should I use other type of buttons instead of the round ones?
Thanks
Ashish Gudla
Ashish Gudla 2015년 5월 27일
you need to increment the value to get the count of times user clicked a radio button. you could do something like this:
val = getappdata(handles.radiobutton3,'result');
setappdata(handles.radiobutton3,'result',val+1);

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Maintain or Transition figure-Based Apps에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by