Borrar filtros
Borrar filtros

Button group alter values

1 visualización (últimos 30 días)
H.Hogarth
H.Hogarth el 18 de Abr. de 2016
Comentada: Rajesh Dubal el 19 de Abr. de 2016
Hi, so i have a popup menu that has the data stored within it as different cases. However i also have a button group which i want to use to change the units of the data and replot it. The first section is all fine, it plots the graph as i want it, the code can be seen below.
function choose_Callback(hObject, eventdata, handles)
% hObject handle to choose (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
switch get(handles.choose,'Value')
case 1
S.A=8.021;
S.B=1936.01;
S.C=258.451;
S.Tmin=18;
S.Tmax=118;
S.T=S.Tmin:((S.Tmax-S.Tmin)/100):S.Tmax;
case 2
S.A=8.021;
S.B=1936.01;
S.C=258.451;
S.Tmin=18;
S.Tmax=118;
S.T=S.Tmin:((S.Tmax-S.Tmin)/100):S.Tmax;
case 3
S.A=7.11714;
S.B=1210.595;
S.C=229.664;
S.Tmin=-13;
S.Tmax=55;
S.T=S.Tmin:((S.Tmax-S.Tmin)/100):S.Tmax;
end
S.P=10.^(S.A-(S.B./(S.C+S.T)));
plot(S.T,S.P)
set(handles.choose, 'UserData', S);
The problem arrises when i try to use the button group;
function pressureset_SelectionChangedFcn(hObject, eventdata, handles)
% hObject handle to the selected object in pressureset
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
sel_obj = get(handles.pressureset, 'selectedobject');
avial_object = get(handles.pressureset,'children');
if sel_obj==avial_object(1)
set(handles.choose,'value')
elseif sel_obj==avial_object(2)
set(handles.choose,'value', S.P.*(101.325/760))
I get the error undefined variable S.T, any idea how i can bring over the data from the first section? Many Thanks.

Respuestas (1)

Rajesh Dubal
Rajesh Dubal el 18 de Abr. de 2016
The error occurs because the scope of the variable S is locally restricted to the function choose_Callback. What I personally do is save these in the handles structure.
Here is what you can do :
function choose_Callback(hObject, eventdata, handles)
% hObject handle to choose (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
switch get(handles.choose,'Value')
case 1
handles.S.A=8.021;
handles.S.B=1936.01;
handles.S.C=258.451;
handles.S.Tmin=18;
handles.S.Tmax=118;
handles.S.T=S.Tmin:((S.Tmax-S.Tmin)/100):S.Tmax;
case 2
handles.S.A=8.021;
handles.S.B=1936.01;
handles.S.C=258.451;
handles.S.Tmin=18;
handles.S.Tmax=118;
handles.S.T=S.Tmin:((S.Tmax-S.Tmin)/100):S.Tmax;
case 3
handles.S.A=7.11714;
handles.S.B=1210.595;
handles.S.C=229.664;
handles.S.Tmin=-13;
handles.S.Tmax=55;
handles.S.T=S.Tmin:((S.Tmax-S.Tmin)/100):S.Tmax;
end
handles.S.P=10.^(handles.S.A-(handles.S.B./(handles.S.C+handles.S.T)));
plot(handles.S.T,handles.S.P)
set(handles.choose, 'UserData', handles.S);
guidata(hObject, handles); %to update the handles structure
And the button callback
function pressureset_SelectionChangedFcn(hObject, eventdata, handles)
% hObject handle to the selected object in pressureset
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
sel_obj = get(handles.pressureset, 'selectedobject');
avial_object = get(handles.pressureset,'children');
if sel_obj==avial_object(1)
set(handles.choose,'value')
elseif sel_obj==avial_object(2)
set(handles.choose,'value', handles.S.P.*(101.325/760))
guidata(hObject, handles); %to update the handles structure
  2 comentarios
H.Hogarth
H.Hogarth el 18 de Abr. de 2016
Hi, thanks for the quick response, when i select the second button in the button group i no longer get an error but the axis dont update to the new S.P value. Any ideas? Thanks
Rajesh Dubal
Rajesh Dubal el 19 de Abr. de 2016
You need to plot the curve again in the pressureset button callback, because you are not updating the plot anywhere in that callback.

Iniciar sesión para comentar.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by