Axis Labels and title not appearing in app designer

71 views (last 30 days)
I have created an app where you can change the plot types on the axis (eg line, scatter or scatter with average) and can also choose to add a second y-axis (using yy options) or colour axis. On R2019B I did something like the below example when ever I change the plot variables as if i plotted left and right Y axis and then went back to just a left Y Axis it would keep the right Y axis there and the label, this worked perfectly (please note this isnt the exact code and just an example showing what i mean).
cla(UIAxes,'reset')
ylabel(app.UIAxes, app.LeftYAxisDropDown.Value)
xlabel(app.UIAxes, app.XAxisDropDown.Value)
plot(x,y)
Now I have moved to 2020B it wipes all the axis labels and titles even though I haven't changed the code and are still defining them after I reset the axis.

Accepted Answer

Image Analyst
Image Analyst on 1 Sep 2021
xlabel() and ylabel() take a string. So after the axes handle, you have to give a string, not the index of the selected drop down list. Presumably the string you want to show is in the drop down list. Here is how to get it:
selectedIndex = app.LeftYAxisDropDown.Value;
dropDownItems = app.LeftYAxisDropDown.String; % Get all drop down items into a cell array.
axisLabel = dropDownItems{dropDownItems};
ylabel(app.UIAxes, axisLabel)
selectedIndex = app.XAxisDropDown.Value;
dropDownItems = app.XAxisDropDown.String; % Get all drop down items into a cell array.
axisLabel = dropDownItems{dropDownItems};
xlabel(app.UIAxes, axisLabel)
  1 Comment
Huw Wadkin
Huw Wadkin on 2 Sep 2021
Hi Image Analyst,
I think the .Value of drop down UI is already a string, i could be wrong. After playing around with it myself for some reason the problem is fixed if I define the plot and then the labels, if I defined the labels first it wiped then the plot the labels won't appear? This didn't seem to be the case on 2019b.

Sign in to comment.

More Answers (0)

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!