control of switch button with another switch button

1 visualizzazione (ultimi 30 giorni)
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 ?

Risposta accettata

OCDER
OCDER il 9 Gen 2019
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 Commenti
OCDER
OCDER il 10 Gen 2019
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

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Migrate GUIDE Apps in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by