control of switch button with another switch button

조회 수: 3 (최근 30일)
belhassan haj mansour
belhassan haj mansour 2019년 1월 9일
댓글: OCDER 2019년 1월 10일
HELLO
im trying to control a rockerswitch button with another one in app designer
details: i have rockerswitch1 in the position 'off' and rockerswitch2 also in position 'off' . what i need is when i put rockerswitch1 in position 'on', the rockerswitch 2 become in the position 'on' too but i can't find the right function to do so. Also i tried to properly call the handle and use it within the if statement but i couldn't do it the right way
CAN ANYONE HELP ME WITH THIS PLEASE ?

채택된 답변

OCDER
OCDER 2019년 1월 9일
function test
Gx = uifigure('Position',[100 100 350 275]);
% Create switch1
UI1 = uiswitch(Gx, 'rocker',...
'Tag', 'switch1', ...
'Items', {'On', 'Off'},...
'Position', [140 160 20 45],...
'ValueChangedFcn', @switchMoved);
% Create switch2
UI2 = uiswitch(Gx, 'rocker',...
'Tag', 'switch2', ...
'Items', {'On', 'Off'},...
'Position', [180 160 20 45],...
'ValueChangedFcn', @switchMoved);
%Use this callback function to run when there is a value changed in switch1 or 2
function switchMoved(src, event)
switch src.Tag
case 'switch1' %change switch2 too
UI2.Value = UI1.Value;
case 'switch2' %change switch1 too
UI1.Value = UI2.Value;
end
end
end
  댓글 수: 3
OCDER
OCDER 2019년 1월 10일
You can't put a function within a switch statement. Also, consider simplifying your cases for your switch. They're rather long... Lastly, upload the code, not an image of your code. It's easier if we can copy paste code, and it'll be easier for you too to Ctrl+C and Ctrl+V instead of PrintScreening.
A callback function is summoned when you do an event (like clicking the rocker switch). Try the test function I gave you first before building app. Does it work? Your version 2018a supports it.
switch Option
case 'A'
case 'CHECK THIS CASE STATEMENT AS IT IS VERY LONG & WILL MAKE LIFE DIFFICULT'
function switchedove(varargin) %NOPE. This can't be done.
end
end
end

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by