How do you align numbers within a column in UItable?
조회 수: 29 (최근 30일)
이전 댓글 표시
We're using GUIDE to build financial applications for investment bankers. They expect to see a column of dollar figures right aligned but there seems to be no obvious way to right align characters in a column in UItable. Any help would be GREATLY appreciated!!!
댓글 수: 0
채택된 답변
Walter Roberson
2011년 3월 10일
Golf'ing Oleg's solution:
dat = {'23234.43 $'; '234.43 $'; '0.23 $'};
dat = cellfun(@(s) sprintf('%*s',max(cellfun(@length,dat)),s),dat);
and then pick up at "Create table".
댓글 수: 3
추가 답변 (2개)
Oleg Komarov
2011년 3월 10일
I came up with this solution:
dat = {'23234.43 $'; '234.43 $'; '0.23 $'};
Pad string amounts with blanks
l = cellfun(@length,dat);
dat = num2cell([arrayfun(@blanks,max(l)-l,'un',0) dat],1);
dat = strcat(dat{:});
Create table with courier font
f = figure('Position',[200 200 400 150]);
cnames = 'Amounts';
rnames = {'First','Second','Third'};
t = uitable('Parent',f,'Data',dat,'ColumnName',cnames,...
'RowName',rnames,'Position',[20 20 360 100],...
'fontname','courier');
Oleg
댓글 수: 2
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!