Formatting Numbers in App Designer's UITable

조회 수: 39 (최근 30일)
Felipe Dicker
Felipe Dicker 2025년 1월 10일
댓글: Olof 2025년 9월 17일 11:18
Is there a way to format numbers in a UITable in App Designer? For example, can I have the second row's format be '%.1f' and cell (4,2)'s format be '%.4e'? I don't want to use strings because I need to keep the table's numerical data.

채택된 답변

Walter Roberson
Walter Roberson 2025년 1월 10일
You have two possibilities here:
  1. format as strings
  2. independently round() each column to the appropriate number of digits
The problem with strings is that a) the table no longer contains full-precision data; and b) you lose the ability to force edits to be strictly numeric format (though with CellEditCallback you can post-process and remove the unacceptable portions of the entry.)
The problem with round() is that a) the table no longer contains full-precision data; and b) trailing zero decimal places will not be displayed, so you cannot force the equivalent of %.4f
There is no mechanism that preserves the full-precision values inside the uitable but displays the data with custom format. You can set 'ColumnFormat' for individual entries to be 'short' but that is not so satisfactory.
  댓글 수: 2
Felipe Dicker
Felipe Dicker 2025년 1월 10일
Unfortunate. Thank you anyway.
Olof
Olof 2025년 9월 17일 11:18
There is aslo a non-satisfactory option as well, to set two decimals :
app.myUITable.ColumnFormat( specify what columns here )={'bank'}
Another not so satisfactory workaround is to keep full numerical representation in UITable.UserData.myTable (in the shadows of the object, or anywhere else for that matter) and displayed string data in UITable.Data where each cell can show desired number formatting using string conversion as mentioned above. Callbacks for the cell edit will have to do the handling/conversion between the tables. This works poorly when user copy-and-paste to/from the UItable, or at least it need very complicated handling of that event.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품


릴리스

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by