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

2 vues (au cours des 30 derniers jours)
Dominique
Dominique le 3 Août 2023
Commenté : dpb le 7 Août 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 commentaires
Dominique
Dominique le 7 Août 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 le 7 Août 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.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Categorical Arrays dans Help Center et File Exchange

Produits


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by