[app.UITableFilteredTable.Data]=Table_HistoricalTable_Struct(app.Eq);
x = [{90} repmat({60},1,size(app.UITableFilteredTable.Data,2)-1)];
app.UITableFilteredTable.ColumnWidth =x;
app.UITableFilteredTable.ColumnName ={};
i try to use : round(v*100)/100 in table field's but it doesn't work

 채택된 답변

Voss
Voss 2023년 8월 4일
A random matrix:
M = rand(10,2);
A uitable showing that matrix (defaults to 4 decimal places):
figure()
uitable('Data',M);
Another uitable with the numbers rounded to two decimal places:
figure()
uitable('Data',round(M,2));
Another uitable with rounded data, using character vectors instead of numbers:
figure()
t = uitable('Data',compose('%.2f',M),'ColumnFormat',{'char','char'});
Since you are using a uifigure, you can also add a uistyle to the uitable that sets the HorizontalAlignment of the text to the right.
s = uistyle('HorizontalAlignment','right');
addStyle(t,s)

댓글 수: 6

i try this:
[app.UITableFilteredTable.Data]=Table_HistoricalTable_Struct(app.Eq);
x = [{90} repmat({60},1,size(app.UITableFilteredTable.Data,2)-1)];
app.UITableFilteredTable.ColumnWidth =x;
app.UITableFilteredTable.ColumnName ={};
app.UITableFilteredTable.ColumnFormat =repmat({'char'},1,size(app.UITableFilteredTable.Data,2)-1);
Warning: 'ColumnFormat' value has no effect when 'Data' value is a table array.
Warning: 'ColumnFormat' value has no effect when 'Data' value is a table array.
and where i can i write it ? (compose('%.2f',M),)
Since your uitable's Data is a table, I think you'll have to change the data in the table variable itself.
T = Table_HistoricalTable_Struct(app.Eq);
str = compose('%.2f',T{:,2:end});
T = convertvars(T,T.Properties.VariableNames(2:end),'cell');
T{:,2:end} = str;
app.UITableFilteredTable.Data = T;
Note that now the data in columns 2-end of your uitable is character vectors instead of numbers, and if you convert it to numbers again, e.g., to do some calculation with it, you've lost precision beyond 2 decimal places. In other words, you are changing the actual data in the table, not just how it's displayed. I don't know of a way to change the display without changing the underlying data.
pipin
pipin 2023년 8월 4일
thank
pipin
pipin 2023년 8월 5일
hi,it's possibile to set HorizontalAlignment all element but not column n.2?
Yes
t = app.UITableFilteredTable; % your uitable
s = uistyle('HorizontalAlignment','center') % 'center' or whatever you want them to be
addStyle(t,s,'column',[1 3:size(t.Data,2)]) % add style s to columns 1 and 3:end of uitable t
pipin
pipin 2023년 8월 5일
thank you

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Data Import and Network Parameters에 대해 자세히 알아보기

질문:

2023년 8월 4일

댓글:

2023년 8월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by