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

2 views (last 30 days)
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');

Answers (1)

Ashish Gudla
Ashish Gudla on 27 May 2015
Edited: Ashish Gudla on 27 May 2015
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 Comments
Isabel
Isabel on 27 May 2015
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 on 27 May 2015
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);

Sign in to comment.

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!