Control number of decimal places in app designer uitable with table array data
79 views (last 30 days)
Show older comments
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.
0 Comments
Accepted Answer
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.
More Answers (0)
See Also
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!