uint16 dimensions work in tiledlayout but not in nexttile

Try running the following sequence of commands, which gets an error:
numXTiles = uint16(2);
numYTiles = uint16(1);
mainTile = numXTiles * numYTiles + 1;
mainYTiles = numYTiles * 2;
numYTiles = numYTiles + mainYTiles;
tiles = tiledlayout(numYTiles, numXTiles);
ax = nexttile(tiles, mainTile, [mainYTiles numXTiles]);
Then try this sequence, which doesn't get an error:
numXTiles = 2;
numYTiles = 1;
mainTile = numXTiles * numYTiles + 1;
mainYTiles = numYTiles * 2;
numYTiles = numYTiles + mainYTiles;
tiles = tiledlayout(numYTiles, numXTiles);
ax = nexttile(tiles, mainTile, [mainYTiles numXTiles]);
The documentation for nexttile says that the tilelocation and span "are positive whole numbers".
I get this error when using uint16:
Error using +
Integers can only be combined with integers of the same class, or scalar doubles.
Error in nexttile
Error in nexttile

3 Commenti

DGM
DGM il 14 Nov 2022
Modificato: DGM il 14 Nov 2022
Anyone is free to inform me otherwise, but I don't see why that's not a bug. Same behavior in R2019b.
I can't open the .p file and find out what it's not checking, but if you feed it something that's not an integer, the error message suggests that parameters must be "integers less than intmax".
If the arguments are nominally integers, then the function should accept integers.
I agree, it looks like a bug. But workaround is easy (cast to input double)
I work at MathWorks and have forwarded this feedback to the relevant team.

Accedi per commentare.

Risposte (1)

The error looks like a bug. I was able to reproduce the error in MATLAB R2022a.
I observed that this has been resolved from MATLAB R2023b onwards. You can consider uprading to a more recent version to resolve this issue.
Thanks.

Prodotti

Release

R2022a

Richiesto:

il 14 Nov 2022

Community Treasure Hunt

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

Start Hunting!

Translated by