How can be the variable of one slider be independent on variable of another slider , initially ?

조회 수: 1 (최근 30일)
Hello all, I am using two sliders for generating cylinder (for altering R and H).code is -
function slider1_Callback(hObject, eventdata, handles)
global a; global b;
a=get(hObject,'Value');
[xc,yc,zc] = cylinder(a);
zc(2,:)=b;
axes(handles.cylinder);
axis equal;
surf(zc,xc,yc,'Facecolor',[1 1 1]);
function slider2_Callback(hObject, eventdata, handles)
global b; global a;
b=get(hObject,'Value');
[xc,yc,zc] = cylinder(a);
zc(2,:)=b;
axes(handles.cylinder);
axis equal;
surf(zc,xc,yc,'Facecolor',[1 1 1]);
when I slide first slider it gives error because initially second slider does not have any value ('b' is undefined). So when I change value of 2nd slider then 1st slider then it generates cylinder . How could I make 1st slider independent of b initially ? means when I slide first slider in the beginning it should response , should not give the error. Thank you .

채택된 답변

Walter Roberson
Walter Roberson 2016년 2월 15일
Before
zc(2,:)=b;
add
if isempty(b)
b = get(handles.slider2, 'Value');
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by