Why can't uitable accept strings in 2018b update while uicontrol can accept strings?

2 次查看(过去 30 天)
With the release of MATLAB 2018b, a lot of function inputs accept strings as well as char arrays. I'm converting an application with programmatic UI elements and decided to convert these to strings as much as possible as well as using strings is now encouraged by MATLAB. This goes fine for most UI elements, for example:
uicontrol(f, "Position", [0.2 0.2 0.2 0.2], "String", "Hello")
uicontrol(f, "String", "Hello", "Tag", "Test String")
However, using quotes for uitable puts up a variety of errors, for example:
uitable(f, "Tag", "Test Table")
produces both a warning and an error, while
uitable(f, 'Tag', 'Test Table')
is fine. Other series of parameters with quotes produce different errors. And, compared to other UI elements, uitable seems less willing to have strings for its properties. The ColumnName property accepts a string, but ColumnFormat does not.
Is there a particular reason that uitable was mostly left out when it came to the ability to use strings?
  3 个评论
Craig DeAlmeida
Craig DeAlmeida 2018-9-26
编辑:Craig DeAlmeida 2018-9-26
Thanks, Adam, for hopping in on this one. Not all properties accept strings, it seems. For example,
uitable(f, 'ColumnWidth', "auto")
does not work...it must be 'auto'.

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2018-9-25
TL;DR -- it's a bug.
This has to do with backwards compatibility for the pre-R2008a undocumented built-in uitable. The parsing code to check whether the old version is needed uses ischar() on the first argument after the figure handle, instead of testing for either char or string objects. The other property name arguments are tested with code that can handle either character vectors or string scalars.
Thus, with the String as the first property name, uitable believes that it needs to invoke the old undocumented uitable, and passes all the arguments to it to figure out.
It was probably thought there was not be much reason to update the old built-in undocumented uitable, as it would be expected to be essentially unused. They probably didn't anticipate overlooking something in the decision code of whether to invoke it...
If I read the code correctly, the old built-in version will be also invoked if you name any of the following properties in the uitable call:
{'columnnames', 'datachangedcallback', 'enabled', 'gridcolor', 'numcolumns', 'numrows', 'rowheight'}
Exact matches are done for these, which makes a difference between the new uitable has a property named 'columnname' without the 's'
The documentation on changes from the old built-in version to the new version is at https://www.mathworks.com/help/releases/R2012a/techdoc/uitools_csh/error_pages/uitable_errorpage.html
I will report this to Mathworks.
  4 个评论
Yair Altman
Yair Altman 2018-10-2
编辑:Yair Altman 2018-10-2
"It was probably thought there was not be much reason to update the old built-in undocumented uitable, as it would be expected to be essentially unused..."
If this was indeed the reasoning, then I strongly disagree: the old uitable, to this very day, is still significantly preferable to the new uitable in terms of performance and customizability. It seems that once Mathworks released the new (documented) uitable a decade ago, they didn't bother bringing it up to par with the old (undocumented) version and basically moved on to other projects. The new uitable is inferior in many aspects to the old one, and so I rarely use the new version. I really hope MathWorks does not discontinue the old uitable anytime soon.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

标签

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by