MATLAB: Error making a buttongroup & radio buttons work.

errorguihelpode45radiobutton

Hi. So I've been trying to learn lot about GUI but I've been having a hard time with it. So I have a code in a workspace separate from my GUI called Proy. My coding involves solving a concentration problem using ODE. In my GUI, I call my other file like so: @Proy. Here is my Proy code:
function fun = Proy(t,x)
global tiempo
global k
Ca1 = x(1);
Cb1 = x(2);
Ca2 = x(3);
Cb2 = x(4);
Cao = 20;
fun (1) = 1/tiempo*(Cao - Ca1) - (k*Ca1);
fun (2) = -1/tiempo*Cb1 + (k*Ca1);
fun(3) = 1/tiempo*(Ca1 - Ca2) - (k*Ca2);
fun (4) = 1/tiempo*(Cb1 - Cb2)-(k*Ca2);
fun = fun';
Here is my GUI code: (This code is under my calculate pushbutton callback)
global tiempo
global te
global R
global k
contenido = get(handles.opcion,'Value');
switch contenido
case 1
k = 0.0157;
case 2
k = 0.12;
case 3
k = 0.089;
case 4
k = 0.35;
end
tiempo = eval(get(handles.residencia,'String'));
xo = [0 0 0 0];
if tiempo <= 10
tint = [0,100];
[t,x] = ode45 (@Proy, tint, xo);
elseif tiempo <= 45
tint = [0,250];
[t,x] = ode45 (@Proy, tint, xo);
else
tint = [0,450];
[t,x] = ode45 (@Proy, tint, xo);
end
switch (get(eventdata.NewValue,'Tag'))
case 'sitime'
te = eval(get(handles.TE,'String'));
Ca1e = x(te,1);
Cb1e = x(te,2);
Ca2e = x(te,3);
Cb2e = x(te,4);
case 'notime'
Ca1 = x(:,1) ;
Cb1 = x(:,2);
Ca2 = x(:,3);
Cb2 = x(:,4);
C = [Ca1 Cb1 Ca2 Cb2];
end
The tags for the radio buttons are: sitime and notime
Whenever I run my program, it shows me the following error:
No appropriate method, property, or field 'NewValue' for class 'matlab.ui.eventdata.ActionData'.
Error in trialproy_>calcular_Callback (line 135)
switch (get(eventdata.NewValue,'Tag'))
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in trialproy_ (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)trialproy_('calcular_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.|
And here is a screenshot of my GUI:
%

Best Answer

Notice the line
Error while evaluating UIControl Callback.
So you are executing a uicontrol callback. If you look at https://www.mathworks.com/help/matlab/creating_guis/add-code-for-components-in-callbacks.html then if you read through you can see that eventdata is reserved for all uicontrol types. eventdata has a NewData property for uibuttongroup and for uitable, but not for uicontrol.
If you want something to happen as a result of clicking on a togglebutton or radio button managed by a uibuttongroup then you need to have the callback against that item, and that callback needs to make whatever changes to variables that are necessary.
If you want to read out the current state of a uibuttongroup while you are executing a uicontrol callback, then the uibuttongroup will not be executing and the eventdata will be the reserved value appropriate for uicontrol. NewData will not be meaningful at that point as the change to value will already have gone by: you can just look at the uibuttongroup Value to find out which button is currently pressed.