How do I assign a variable within a GUI that I can use late in the GUI?

5 views (last 30 days)
Hi,
I am trying to make a GUI in GUIDE that will have 2 edit boxes and either 3 sets of radio boxes or 3 popup menu (with 2 or three options in each set). Initially I was trying to create 3 popup menus, but I couldn't get this to work, so I switched to radio boxes which now I can't get them to work either.
My issue is that I can assign a variable within a callback, but I cannot figure out a way to be able to use it late on in my GUI.
Initially when I was using popup menus I had this code:
% --- Executes on selection change in GraphChoice.
function GraphChoice_Callback(hObject, eventdata, handles)
% hObject handle to GraphChoice (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns GraphChoice contents as cell array
% contents{get(hObject,'Value')} returns selected item from GraphChoice
val=get(hObject, 'Value');
str=get(hObject, 'String');
switch str{val}
case 'GRF'
handles.current_data=handles.GRF;
case 'Angles'
handles.current_data=handles.Angles;
case 'Moments'
handles.current_data=handles.Moments;
end
guidata(hObject,handles);
% --- Executes on button press in CalculatePushButton.
function CalculateGraphs_Callback(hObject, eventdata, handles)
% hObject handle to CalculatePushButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
Subject=(get(handles.SubjectNumber, 'string'));
GraphType= handles.current_data
And this worked fine until I added a second popup menu and both popup menus only produced errors. I figured it stopped working because of my use of current_data, but if I used any other variable name or reassigned the variable name it wouldn't work.
I didn't really have anymore success using radio buttons. I put my 3 radio boxes into a panel and here is the code for it :
function GraphType_SelectionChangeFcn(hObject, eventdata, handles)
% hObject handle to the selected object in unitgroup
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles.Graphtype= 'Unknown Graph';
if (hObject == handles.GraphTypeGRF)
handles.GraphType= 'GRF';
elseif (hObject == handles.GraphTypeAngle)
handles.GraphType= 'Angle';
else
handles.GraphType= 'Moment';
end
guidata(hObject,handles)
% --- Executes on button press in CalculateButton.
function CalculateButton_Callback(hObject, eventdata, handles)
% hObject handle to CalculateButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
Subject= handles.SubjectNumber
GraphType= handles.GraphType
When the GraphType for both cases (the radio boxes and popup menus) were displayed they only showed an initial value that the GraphType was assigned to (using the same notation as shown here) in the beginning.
On a slight side note, if I used radio buttons I only want the user to be able to select one option from a panel at a time, but I do not know how to do this.
I will take advice for either option but pop up menus are probably preferred.
Thanks in advance!

Answers (0)

Categories

Find more on Graphics Object Properties 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!