MATLAB Answers

Error in nexttile after adding colorbar for whole tiledlayout

4 views (last 30 days)
Linus
Linus on 21 Nov 2020
Answered: Srivardhan Gadila on 28 Nov 2020
I'm encountering this error on Matlab R2020b:
f = figure;
t = tiledlayout(f, 'flow');
nexttile %adding any two plots
plot(1:100)
nexttile
plot(1:100)
cb = colorbar; %adding colorbar
cb.Layout.Tile = 'East' %following the documentation on how to add colorbar for entire tiledlayout
So far, everthing works great. The colorbar belongs to the second axes but it is on the right side of the entire tiledlayout and it looks how it is supposed to. But when I now try to alter the first axes with
nexttile(1)
I get this error message
"Operands to the || and && operators must be convertible to logical scalar values.
Error in nexttile"
Does anyone have a clue what's going on there?

  0 Comments

Sign in to comment.

Answers (1)

Srivardhan Gadila
Srivardhan Gadila on 28 Nov 2020
You can try storing the axes when you create a new tile and use the stored axes later as follows:
f = figure;
t = tiledlayout(f, 'flow');
ax1 = nexttile %adding any two plots
plot(1:50)
ax2 = nexttile
plot(1:100)
cb = colorbar;
cb.Layout.Tile = 'East';
% you can make use of the stored axes ax1 and ax2
For more information you can refer to the Examples of the nexttile.

  0 Comments

Sign in to comment.

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!