Why can't uitable accept strings in 2018b update while uicontrol can accept strings?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Craig DeAlmeida
el 25 de Sept. de 2018
Editada: Yair Altman
el 2 de Oct. de 2018
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 comentarios
Craig DeAlmeida
el 26 de Sept. de 2018
Editada: Craig DeAlmeida
el 26 de Sept. de 2018
Respuesta aceptada
Walter Roberson
el 25 de Sept. de 2018
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 comentarios
Yair Altman
el 2 de Oct. de 2018
Editada: Yair Altman
el 2 de Oct. de 2018
"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.
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!