Multiple Row Xlabels in Matlab App Designer UIFigure UIAxes

Hi there,
I am trying to figure out the simplest/cleanest way to place multiple row (in my case - two rows) xlabels into a UIFigure in Matlab App Designer.
Thanks!

Answers (1)

fig = figure;
app.UIAxes = uiaxes(fig);
You can place the following line in the startup function of your app.
xlabel(app.UIAxes,{'xlabel 1';'xlabel 2'})

6 Comments

Kevin - apologies for not being more clear. I am specifically looking to do two rows per xticklabel. So inserting text for 0,0.2,0.4,0.6,0.8,1 where each tick has two strings in two separate rows.
Below is borrowed from Adam Danz in this MATLAB Answer question:
Be sure to upvote his Answer in the link above if this helps.
row1 = {'White' 'Green' 'Red' 'White' 'Green' 'Red'};
row2 = {'East' 'East' 'East' 'West' 'West' 'West'};
row3 = 10.5:15.5;
labelArray = [row1; row2; compose('%.1f',row3)];
tickLabels = strtrim(sprintf('%s\\newline%s\\newline%s\n', labelArray{:}));
fig = figure;
app.UIAxes = uiaxes(fig);
app.UIAxes.XTick = 1:6;
app.UIAxes.XLim = [0,7];
app.UIAxes.XTickLabel = tickLabels;
xlabel(app.UIAxes,{'Color';'Direction';'Value'})
Thanks Kevin - I had tried this one originally. I have followed this exactly but in the app, rather than creating a new line for each row - it has WhitenewlineEastnewline10.5 (and the same for the rest) on each x-tick.
I tested the attached app on R2023a and R2021b. It works fine for me. I do not have R2021a currently installed to test to see if it was a version issue.
Ah ok - I just opened that on my computer with 2021a and that must be the issue. Thanks for walking through this with me - appreciate it!
@Gillian Weir it looks like your tick label interpreter is set to none or latex. This solution requires a tex interpreter.
app.UIAxes.TickLabelInterpreter= 'tex';

Sign in to comment.

Categories

Find more on Develop Apps Programmatically in Help Center and File Exchange

Products

Release

R2021a

Asked:

on 22 Mar 2023

Commented:

on 24 Mar 2023

Community Treasure Hunt

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

Start Hunting!