필터 지우기
필터 지우기

I have a problem aligning text in uitable due to the data type.

조회 수: 1 (최근 30일)
Yasmin Samy
Yasmin Samy 2019년 5월 10일
댓글: Yasmin Samy 2019년 5월 12일
Hi all,
I have a uitable in my figure and can`t seem to adjust the alignment of the text. Apparently, from the documenation (https://www.mathworks.com/help/matlab/ref/matlab.ui.control.tableappd-properties.html), char is automatically displayed justified to the left and the numeric to the right.
In my code, i converted num2cell the 4 arrays and then combined them by horzcat to get the final table to use. This is what i got: All the columns to the left except the N is to the right. Can anyone help me adjust this please? Either by working on data type, alignments in uitables, or any other solution that makes the tables readable instead of looking confusing! Thanks
uit.PNG
  댓글 수: 4
Walter Roberson
Walter Roberson 2019년 5월 11일
Instead of the [505 etc] you could put a variable that had the numeric values.
However, this approach is useless to you, as string() and compose() were not added until R2016b.
arrayfun(@(x) sprintf('%-3s', sprintf('%.3g',x)), YourArray, 'uniform', 0)
However, %.3g is perhaps not suitable for your last column.
You can sprintf uniform 0 each column by itself, with whatever numeric format and string width you want.
There are certainly other ways to get left justification. One way is to write, for example,
LJ = @(S, N) [S, blanks(N-strlen(S))];
arrayfun(@(x) LJ(sprintf('%.3g', x), 3), YourArray, 'uniform', 0)
but if you are going to be doing columns separately and putting them together then,
arrayfun(@(x) sprintf('%-3d', x), YourArray(:,1), 'uniform', 0)
Yasmin Samy
Yasmin Samy 2019년 5월 12일
Thanks that works!!!

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

제품


릴리스

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by