For uicontrol, why can't "UserData" property hold a structure but 'UserData' can?
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Rik
2018-9-26
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!