- Provide each of the 6 switches with a unique name or tag (see image below).
- Assign the same callback function to all 6 on-off switches.
- Within the switch-callback function, you can use the inputs to determine which switch was activated based on the uniqe name/tag. event.Source.Tag
- Add a private property to the app named "ActiveSwitch" (you can rename it).
- One of the switches should be on by default and others should be off. This can be done in design mode or from within DesignView or within the app's startup function. Copy the tag of the switch that's on to the ActiveSwitch property.
- When a switch is activated, the callback function will turn off the other 5 switches and will update the ActiveSwitch property with the switch's tag. This property will keep track of which swtich is active (see code below).
- When it's time to do the plotting, just use the tag stored in ActiveSwitch to determine which axes to use.
Select one of multiple UIAxes do display it at specific position
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Marcus
el 10 de Jun. de 2021
Comentada: Adam Danz
el 14 de Jun. de 2021
Hi everyone,
im working on an app in app designer to evaluate large and different excel files and plot various variables against each other. So far i plotted them in one UIAxes and it worked pretty well but now i try to let the user select one out of six UIAxes where he can plot the variables. I would like to display 6 smaller UIAxes on the right side of my app and based on the selected switch, it plots the variables in the the selected UIAxes and displays the UIAxes at a defined position just a little larger than on the right side.
Any idea how i can enlarge and display the selected UIAxes on a defined position based on the selected switch?
The UIAxes on the left side should be one of the six UIAxes on the right, based on the switch position above the six UIAxes.
0 comentarios
Respuesta aceptada
Adam Danz
el 10 de Jun. de 2021
Editada: Adam Danz
el 14 de Jun. de 2021
Apply the plot to the selected axes
An example app is attched. It only contains 4 switches and shows how to achieve steps 1-6.
The callback function SwitchValChange is assigned to all switches:
% Value changed function: Switch1, Switch2, Switch3, Switch4
function SwitchValChange(app, event)
value = event.Source.Value;
if strcmpi(value,'off')
% Users can only turn on a switch, they cannot turn one off,
% that is done automatically when another switch is activated.
event.Source.Value = 'On';
return
end
% Update active switch tag
app.ActiveSwitch = event.Source.Tag;
% Turn off all other switches
switchHandles = [app.Switch1, app.Switch2, app.Switch3, app.Switch4];
tags = get(switchHandles, 'Tag');
isActive = strcmpi(tags, event.Source.Tag);
set(switchHandles(~isActive), 'Value', 'Off')
end
How to assign tags to switches:
Enlarge the selected axes
I don't fully understand this part, "...displays the UIAxes at a defined position just a little larger than on the right side". Have you tried updating the axes position properties?
2 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Develop Apps Using App Designer 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!