Control number of decimal places in app designer uitable with table array data

65 views (last 30 days)
I am using a uitable created using app designer.
The Data property is assigned to a MATLAB table array.
Some of the columns in this table array are numeric, others are logicals.
For the numeric columns I would like to limit the number of decimal places that are displayed. Currently it displays 4 decimal places, which is excessive for my application, and would make it difficult for the user to quickly scan values.
I see from the uitable documentation, that when the Data property is set to use a table array the ColumnFormat property can not be used. How then can I limit the number of decimal places?
I have already tried changing the number format from the command line in my command window for example format bank. This did not seem to have any effect on the values displayed in the uitable.
One work around would be to convert all of my numeric data to appropriately formatted strings, and then convert back to numeric data when I need to read it out of the table (after a user edits it). This seems very inelegant. I would really prefer to leave the numeric data as numeric data and not go back and forth to strings. Please let me know if you can suggest any other solution to this problem.

Accepted Answer

Juhi Singh
Juhi Singh on 4 Sep 2020
Unfortunately, the best way to achieve the result would be to convert it to a string. Please refer to the following link for more information: https://www.mathworks.com/help/rptgen/ug/format_numbers_in_a_table.html
For more information regarding the issue, refer to the following:https://www.mathworks.com/matlabcentral/answers/79928-reduce-precision-of-a-number
Other possible alternatives could be:
A possible workaround will be to extract the column, convert it to array using 'table2array()' function and then use 'digits()' and 'vpa()' to set the number of significant digits required. This data when stored in the table will be displayed as [1x1 sym]
You could also use round() or chop() with the number of digits you want it to be rounded off to. But that will still have trailing '0's and display 4 decimal places.
  1 Comment
Jon
Jon on 4 Sep 2020
Hi Juhi,
Thanks for your response.
I do not have the symobolic toolbox, so I don't think the digits and vpa options are available.
So, unfortunately, it is as I thought, the only way to do this is by changing the variables back and forth from numbers to strings.
I also received a suggestion from one of your colleagues on the support team (I sent a similar question in to MATLAB support) that I could assign the Data property to an array rather than a table. This would at least allow some degree of control of the format using the ColumnFormat property (which is not applicable when the Data property is assigned to a table) In particular I could set the numeric columns to have a "bank" format which would at least limit the number of decimal places to two (not ideal but better than 4). In addition, by setting the format of the columns in the data numerical which contained 1's and to "logical" I could still get the nice check boxes.
In the end though we agreed, that all of this was quite awkward and the the ability to control the number of decimal places should be put in wish list for the the development team.

Sign in to comment.

More Answers (0)

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!