For uicontrol, why can't "UserData" property hold a structure but 'UserData' can?
1 view (last 30 days)
Show older comments
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?
0 Comments
Accepted Answer
Rik
on 26 Sep 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.
More Answers (0)
See Also
Categories
Find more on Migrate GUIDE Apps in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!