MATLAB Answers

Select one of multiple UIAxes do display it at specific position

2 views (last 30 days)
Marcus on 10 Jun 2021
Commented: Adam Danz on 14 Jun 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.

Accepted Answer

Adam Danz
Adam Danz on 10 Jun 2021
Edited: Adam Danz on 14 Jun 2021
Apply the plot to the selected axes
  1. Provide each of the 6 switches with a unique name or tag (see image below).
  2. Assign the same callback function to all 6 on-off switches.
  3. 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
  4. Add a private property to the app named "ActiveSwitch" (you can rename it).
  5. 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.
  6. 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).
  7. When it's time to do the plotting, just use the tag stored in ActiveSwitch to determine which axes to use.
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';
% 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')
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?

More Answers (0)

Community Treasure Hunt

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

Start Hunting!