Button group alter values
조회 수: 2 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
답변 (1개)
Rajesh Dubal
2016년 4월 18일
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
Rajesh Dubal
2016년 4월 19일
You need to plot the curve again in the pressureset button callback, because you are not updating the plot anywhere in that callback.
참고 항목
카테고리
Help Center 및 File Exchange에서 Title에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!