Getting wrong sizes for string array. (in App Designer)

2 visualizaciones (últimos 30 días)
Dominique
Dominique el 3 de Ag. de 2023
Comentada: dpb el 7 de Ag. de 2023
I'm coding in App Designer.
Any body knows why the following snippets return different array sizes?
app.col = 5; % array column
% case 1:
app.array_test = strings([100, app.col]); % intention of preallocating an array of size (100,5)
size(app.array_test)
ans = 1×2
100 5
% case 2: here is a problem.
app.array_test = strings([100, app.col + 1 ]); % in App Designer, it still creates size of (100,5). Not (100,6)
size(app.array_test)
ans = 1×2
100 6
% case 3:
k = app.col + 1;
app.array_test = strings([100, k]); % creates size of (100,5) as expected
size(app.array_test)
ans = 1×2
100 6
Why Case 2 does not add new column dynamically in App Designer ?
Thanks.
  6 comentarios
Dominique
Dominique el 7 de Ag. de 2023
Thank you guys @Jon, @dpb and @Mannan Baidi
I couldn't reproduce the error in a seperate app.
But I've used length() several times. So I think @dpb is right. Something must have occured when I called length().
Thanks for checking this question.
I will close this.
dpb
dpb el 7 de Ag. de 2023
length is a very dangerous function in the way most folks use it; if it hadn't been introduced by Cleve originally, it probably wouldn't be defined now as it is; at least with no checking/caveats as it is currently.
Wouldn't be the first to have been "bit" by that behavior. It's not the only way such could happen, of course, but it's one of the more likely ways to get an unexpected result silently.
If it is supposed to be a constant, you could set a dbstop condition if/when the value weren't; unfortunately, I don't think there is a way to set a "if changed" breakpoint explicitly; you have to be able to write a logical expression.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Categorical Arrays en Help Center y File Exchange.

Productos


Versión

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by