How to center all of my data in my UItable in Appdesigner

3 次查看(过去 30 天)
i create a table named 'Flowsheet' and i put in im my app
app.UItable2.data = Flowsheet;
the date appears like this 1.47 e+4
  1. i want to center my data in the mention table
  2. i want to show my data with out this format , i want the 'format bank'

回答(1 个)

Eric Delgado
Eric Delgado 2022-12-10
Try this...
% First issue: transform a numeric value to string, defining your format.
LastName = {'Sanchez';'Johnson';'Li';'Diaz';'Brown'};
Age = [38;43;38;40;49];
Age_string = strsplit(sprintf('%.3f\n', Age), '\n')';
Age_string = Age_string(1:end-1);
T = table(LastName, Age, Age_string)
T = 5×3 table
LastName Age Age_string ___________ ___ __________ {'Sanchez'} 38 {'38.000'} {'Johnson'} 43 {'43.000'} {'Li' } 38 {'38.000'} {'Diaz' } 40 {'40.000'} {'Brown' } 49 {'49.000'}
% Second issue: call uistyle
fig = uifigure;
tab = uitable(fig);
tab.Data = T;
s = uistyle("HorizontalAlignment", "center");
addStyle(tab, s)
  2 个评论
Ali Azizzadeh
Ali Azizzadeh 2022-12-10
Flow_string = strsplit(sprintf('%.3f\n', Flow), '\n')';
Flow_kg_string = strsplit(sprintf('%.3f\n', Flow_kg), '\n')';
D_cons_string = strsplit(sprintf('%.3f\n',D_cons), '\n')';
H2O_string = strsplit(sprintf('%.3f\n', H2O), '\n')';
H2S_string = strsplit(sprintf('%.3f\n', H2S), '\n')';
Temperature_string = strsplit(sprintf('%.3f\n', Temperature), '\n')';
Pressure_string = strsplit(sprintf('%.3f\n', Pressure), '\n')';
Molecular_weight_string = strsplit(sprintf('%.3f\n', Molecular_weight), '\n')';
s = uistyle("HorizontalAlignment",'center','IconAlignment','center');
format bank
app.UITable2.Data(:,1) = StreamNumber;
app.UITable2.Data(:,2) = Flow_string;
app.UITable2.Data(:,3) = Flow_kg_string;
app.UITable2.Data(:,4) = D_cons_string;
app.UITable2.Data(:,5) = H2O_string;
app.UITable2.Data(:,6) = H2S_string;
app.UITable2.Data(:,7) = Temperature_string;
app.UITable2.Data(:,8) = Pressure_string;
app.UITable2.Data(:,9) = Molecular_weight_string;
tab = app.UITable2;
addStyle(tab, s)
this is portion of my code
i have this error when the code below is run
"Conversion to double from cell is not possible."
app.UITable2.Data(:,1) = StreamNumber;
app.UITable2.Data(:,2) = Flow_string;
app.UITable2.Data(:,3) = Flow_kg_string;
app.UITable2.Data(:,4) = D_cons_string;
app.UITable2.Data(:,5) = H2O_string;
app.UITable2.Data(:,6) = H2S_string;
app.UITable2.Data(:,7) = Temperature_string;
app.UITable2.Data(:,8) = Pressure_string;
app.UITable2.Data(:,9) = Molecular_weight_string;
Eric Delgado
Eric Delgado 2022-12-11
You have to ignore the last element of the conversion...
Age = [38;43;38;40;49]
Age = 5×1
38 43 38 40 49
Age_string = strsplit(sprintf('%.3f\n', Age), '\n')'
Age_string = 6×1 cell array
{'38.000'} {'43.000'} {'38.000'} {'40.000'} {'49.000'} {0×0 char}
% The last element is {''}... ignore it, indexing 1:end-1
Age_string = Age_string(1:end-1)
Age_string = 5×1 cell array
{'38.000'} {'43.000'} {'38.000'} {'40.000'} {'49.000'}
% In your case...
app.UITable2.Data(:,1) = StreamNumber;
app.UITable2.Data(:,2) = Flow_string(1:end-1);
app.UITable2.Data(:,3) = Flow_kg_string(1:end-1);
app.UITable2.Data(:,4) = D_cons_string(1:end-1);
app.UITable2.Data(:,5) = H2O_string(1:end-1);
app.UITable2.Data(:,6) = H2S_string(1:end-1);
app.UITable2.Data(:,7) = Temperature_string(1:end-1);
app.UITable2.Data(:,8) = Pressure_string(1:end-1);
app.UITable2.Data(:,9) = Molecular_weight_string(1:end-1);

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Develop Apps Using App Designer 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by