필터 지우기
필터 지우기

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'.
Adam Danz
Adam Danz 2018년 9월 26일
Yeah, definitely a bug as Walter pointed out.

댓글을 달려면 로그인하십시오.

채택된 답변

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