For uicontrol, why can't "UserData" property hold a structure but 'UserData' can?

1 visualización (últimos 30 días)
While converting code in 2018b to use strings as much as possible, ran into this surprising error:
f = figure;
s.a = 1;
uicontrol(f, "String", "Hello", "UserData", s);
The error is "Incorrect number of input arguments". However, the following do not generate errors:
uicontrol(f, "String", "Hello", 'UserData', s);
or
a = 1;
uicontrol(f, "String", "Hello", "UserData", a);
It seems that UserData as a string when naming the property and giving it a structure causes the trouble.
Any thoughts out there?

Respuesta aceptada

Rik
Rik el 26 de Sept. de 2018
One of the many places where using strings instead of char arrays will trip you up. I haven't searched for one, but I've never yet seen a situation where strings solved a problem in such a simple and elegant way that it warrants rewriting half of Matlab for.
I'd suggest looking if there is already a bug report (and create it if there isn't). They will either solve it in an update to R2018b, or in a later release. Until then, just use char arrays. I'm also still using get and set instead of dot-indexing, because I generally don't need to go multiple levels deep (which is the only situation where dot-indexing is better). Fun fact: in set and get the properties are not case sensitive, while with dot-indexing they are.
  1 comentario
Craig DeAlmeida
Craig DeAlmeida el 27 de Sept. de 2018
I created a bug report as suggested. I think newer MATLAB users (as those around me) will gravitate more towards strings, as the char array treatment of text is an unusual feature of MATLAB. That said, I'm totally used to it and so it was a tough call to change my code, but I think it will ultimately benefit newer users of MATLAB and my code.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.

Productos


Versión

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by