control of switch button with another switch button
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
belhassan haj mansour
el 9 de En. de 2019
Comentada: OCDER
el 10 de En. de 2019
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 comentarios
Respuesta aceptada
OCDER
el 9 de En. de 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 comentarios
OCDER
el 10 de En. de 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
Más respuestas (0)
Ver también
Categorías
Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!