Axis Labels and title not appearing in app designer

83 次查看(过去 30 天)
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.

采纳的回答

Image Analyst
Image Analyst 2021-9-1
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 个评论
Huw Wadkin
Huw Wadkin 2021-9-2
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Axis Labels 的更多信息

标签

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by