MATLAB Answers

control of switch button with another switch button

18 ビュー (過去 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 ?

  0 件のコメント

サインインしてコメントする。

採用された回答

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 件のコメント

belhassan haj mansour
belhassan haj mansour 2019 年 1 月 9 日
it still dosen't work
maybe because i want to use this callback inside of a list box
PS i'm using matalb 2018a
belhassan haj mansour
belhassan haj mansour 2019 年 1 月 9 日
prob.PNG
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 件)

Community Treasure Hunt

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

Start Hunting!

Translated by