Style Property Not Being Recognised
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi all,
I am trying to format a table - border, border colour etc. I am trying to do this programmatically from the Mathwoks page here: https://uk.mathworks.com/help/rptgen/ug/format-tables.html#mw_aa27b9a4-0c98-4bd7-a08d-2bfa3dda0411
However, I keep getting a error saying "The class table has no Constant property or Static method named 'Style'."
From the web page I would input something like this:
table.Style = [table.Style {Border('solid','black','3px')}]
But the above error message is being shown.
Here is my code. I am only interested in formatting the table, so sorry for so much code.
%Structural Properties
E = 2.1E+08;
Ic1 = 22530/100^4;
Ic2 = 14270/100^4;
Ic3 = 5259/100^4;
Ib = 16040/100^4;
Ac1 = 168/100^2;
Ac2 = 113.3/100^2;
Ac3 = 66.28/100^2;
H = 21;
h = 3;
w = 12.7;
% Average second moment of area of coluums
Ic = (2*Ic1 + 2*Ic2 + 3*Ic2)/7
% Average cross-sectional area of columns
Ac = (2*Ac1 + 2*Ac2 + 3*Ac3)/7
% Stiffness of columns of bracing unit 1
Kc1 = 4*12*E*Ic/h^2
% Stiffness of beams
Kb1 = 2*12*E*Ib/(9*h) + 12*E*Ib/(2*h)
% Reduction factor
r1 = Kc1/(Kb1+Kc1)
% Stiffness of one sub-frame
K1 = (1/Kc1 + 1/Kb1)^-1
% Global second moment of area
Ig1 = 2*Ac*1^2 + 2*Ac*10^2
% Second moment of area of one column
I1 = 4*r1*Ic
% Total second moment of area for bending stiffness
If1 = I1 + Ig1
% Parameter kappa
kappa1 = sqrt(K1/(E*I1))
% Parameter kappa*H
kappaH1 = kappa1*H
% deflection due to shear
ys1 = w*H^2/(2*K1)
% deflection due to bending
yb1 = w*H^4/(8*E*If1)
% Deflection due to interaction of shear and bending
yr1 = (w*E*I1)/(K1^2)*(1 + kappaH1*sinh(kappaH1)/(cosh(kappaH1)-1))
% Total deflection
y1 = ys1 + yb1 - yr1
Bracing_Unit1 = [Kc1 Kb1 K1 Ig1 ys1 yb1 yr1 y1]'
Bracing_Unit2 = [Kc1 Kb1 K1 Ig1 ys1 yb1 yr1 y1]'
Core_1 = [Kc1 Kb1 K1 Ig1 ys1 yb1 yr1 y1]'
Core_2 = [Kc1 Kb1 K1 Ig1 ys1 yb1 yr1 y1]'
% Set up table
Labels = {'Column Stiffness','Beam Stiffness','Frame Stiffness','Global Second moment of Area','Shear Deflection','Bending Deflection','Shear/Bending Interaction','Total Deflection'};
T = table(Bracing_Unit1,Bracing_Unit2,Core_1,Core_2,'RowNames',Labels)
table.Style = [table.Style {Border('solid','black','3px')}]
Can someone help please?
Many thanks,
Scott
1 comentario
dpb
el 28 de Jun. de 2024
Editada: dpb
el 29 de Jun. de 2024
I've never had it and don't know just how it works, but that documentation link is for tables generated by the report generator product, and all that stuff doesn't apply to an "ordinary" builtin MATLAB table. It's too bad there's a collision in names here because it looks to be quite a task to keep straight from a quick perusal...
Respuestas (2)
Walter Roberson
el 28 de Jun. de 2024
The code in the example starts with
import mlreportgen.dom.*;
rpt = Document('MyReport','html','MyTemplate');
table = Table(magic(5),'UnruledTable');
This creates a variable named table using mlreportgen.dom.Table()
Your code is using
T = table(Bracing_Unit1,Bracing_Unit2,Core_1,Core_2,'RowNames',Labels)
without the import , and using table instead of Table so you are getting T as a table() object.
8 comentarios
dpb
el 30 de Jun. de 2024
Editada: dpb
el 30 de Jun. de 2024
"The amount of customization you can do for the display of table() objects is very very limited."
All I can think of that can do is use the format function to set the display number format and that is global for the table; not able to set by column/variable. I've been doing a lot of financial stuff recently and so have set to "bank" which is good for the columns that are dollar values, but other columns may be something like a student ID which is an 8-digit integer so adding ".00" to those is annoying. So, I've resorted to converting the SIDs into categorical so they then are displayed looking like integers, but that has the somewhat painful side effect of having to do lookup in the code either by string comparison or by casting the categorical values to numeric first. But, default '%g" is even less pleasing because it switches around how the financial data is displayed.
But, there's nothing one can do about highlighting cells or such amenities; they simply don't exist as such.
Am I overlooking any tricks, Walter?
dpb
el 29 de Jun. de 2024
Editada: dpb
el 29 de Jun. de 2024
What I suspect you're actually looking for here may be the uitable graphics table instead...it has many of the fancy formatting features and can be built from a regular table...it only can live in a uifigure, however. There simply is nothing that has the graphics features that can be displayed in the command window which is a text window, not graphical.
%Structural Properties
E = 2.1E+08;
Ic1 = 22530/100^4;
Ic2 = 14270/100^4;
Ic3 = 5259/100^4;
Ib = 16040/100^4;
Ac1 = 168/100^2;
Ac2 = 113.3/100^2;
Ac3 = 66.28/100^2;
H = 21;
h = 3;
w = 12.7;
% Average second moment of area of coluums
Ic = (2*Ic1 + 2*Ic2 + 3*Ic2)/7;
% Average cross-sectional area of columns
Ac = (2*Ac1 + 2*Ac2 + 3*Ac3)/7;
% Stiffness of columns of bracing unit 1
Kc1 = 4*12*E*Ic/h^2;
% Stiffness of beams
Kb1 = 2*12*E*Ib/(9*h) + 12*E*Ib/(2*h);
% Reduction factor
r1 = Kc1/(Kb1+Kc1);
% Stiffness of one sub-frame
K1 = (1/Kc1 + 1/Kb1)^-1;
% Global second moment of area
Ig1 = 2*Ac*1^2 + 2*Ac*10^2;
% Second moment of area of one column
I1 = 4*r1*Ic;
% Total second moment of area for bending stiffness
If1 = I1 + Ig1;
% Parameter kappa
kappa1 = sqrt(K1/(E*I1));
% Parameter kappa*H
kappaH1 = kappa1*H;
% deflection due to shear
ys1 = w*H^2/(2*K1);
% deflection due to bending
yb1 = w*H^4/(8*E*If1);
% Deflection due to interaction of shear and bending
yr1 = (w*E*I1)/(K1^2)*(1 + kappaH1*sinh(kappaH1)/(cosh(kappaH1)-1));
% Total deflection
y1 = ys1 + yb1 - yr1;
Bracing_Unit1 = [Kc1 Kb1 K1 Ig1 ys1 yb1 yr1 y1]';
Bracing_Unit2 = [Kc1 Kb1 K1 Ig1 ys1 yb1 yr1 y1]';
Core_1 = [Kc1 Kb1 K1 Ig1 ys1 yb1 yr1 y1]';
Core_2 = [Kc1 Kb1 K1 Ig1 ys1 yb1 yr1 y1]';
% Set up table
Labels = {'Column Stiffness','Beam Stiffness','Frame Stiffness','Global Second moment of Area','Shear Deflection','Bending Deflection','Shear/Bending Interaction','Total Deflection'};
hUIF=uifigure;
T=table(Bracing_Unit1,Bracing_Unit2,Core_1,Core_2,'RowNames',Labels);
UT=uitable(hUIF,'Data',T);
%table.Style = [table.Style {Border('solid','black','3px')}]
Well, we can't demo here... :(
But,
hUIF=uifigure;
hUIF.Position(3)=840; % arbitrary width to fit table
UT=uitable(hUIF,'Data',T); % create the uitable in UI figure
UT.Position(3)=UT.Position(3)-2*hUIF.Position(1); % set width to center in figure
Unfortunately, of all the things you can adjust in a uitable about formatting cells and the data within the cells, the outside border style isn't included so if that's mandatory, you're still back to report generator it appears.
2 comentarios
Voss
el 29 de Jun. de 2024
Nitpick: A uitable can in fact live in a figure, but its functionality is more limited than a uitable in a uifigure.
%Structural Properties
E = 2.1E+08;
Ic1 = 22530/100^4;
Ic2 = 14270/100^4;
Ic3 = 5259/100^4;
Ib = 16040/100^4;
Ac1 = 168/100^2;
Ac2 = 113.3/100^2;
Ac3 = 66.28/100^2;
H = 21;
h = 3;
w = 12.7;
% Average second moment of area of coluums
Ic = (2*Ic1 + 2*Ic2 + 3*Ic2)/7;
% Average cross-sectional area of columns
Ac = (2*Ac1 + 2*Ac2 + 3*Ac3)/7;
% Stiffness of columns of bracing unit 1
Kc1 = 4*12*E*Ic/h^2;
% Stiffness of beams
Kb1 = 2*12*E*Ib/(9*h) + 12*E*Ib/(2*h);
% Reduction factor
r1 = Kc1/(Kb1+Kc1);
% Stiffness of one sub-frame
K1 = (1/Kc1 + 1/Kb1)^-1;
% Global second moment of area
Ig1 = 2*Ac*1^2 + 2*Ac*10^2;
% Second moment of area of one column
I1 = 4*r1*Ic;
% Total second moment of area for bending stiffness
If1 = I1 + Ig1;
% Parameter kappa
kappa1 = sqrt(K1/(E*I1));
% Parameter kappa*H
kappaH1 = kappa1*H;
% deflection due to shear
ys1 = w*H^2/(2*K1);
% deflection due to bending
yb1 = w*H^4/(8*E*If1);
% Deflection due to interaction of shear and bending
yr1 = (w*E*I1)/(K1^2)*(1 + kappaH1*sinh(kappaH1)/(cosh(kappaH1)-1));
% Total deflection
y1 = ys1 + yb1 - yr1;
Bracing_Unit1 = [Kc1 Kb1 K1 Ig1 ys1 yb1 yr1 y1]';
Bracing_Unit2 = [Kc1 Kb1 K1 Ig1 ys1 yb1 yr1 y1]';
Core_1 = [Kc1 Kb1 K1 Ig1 ys1 yb1 yr1 y1]';
Core_2 = [Kc1 Kb1 K1 Ig1 ys1 yb1 yr1 y1]';
% Set up table
Labels = {'Column Stiffness','Beam Stiffness','Frame Stiffness','Global Second moment of Area','Shear Deflection','Bending Deflection','Shear/Bending Interaction','Total Deflection'};
hUIF=figure;
T=table(Bracing_Unit1,Bracing_Unit2,Core_1,Core_2,'RowNames',Labels);
UT=uitable('Data',table2array(T));
%table.Style = [table.Style {Border('solid','black','3px')}]
dpb
el 29 de Jun. de 2024
Editada: dpb
el 29 de Jun. de 2024
...
T=table(Bracing_Unit1,Bracing_Unit2,Core_1,Core_2,'RowNames',Labels);
UT=uitable('Data',T);
Error using uitable
Functionality not supported with figures created with the figure function.
Error in uitable (line 53)
thandle = builtin('uitable', varargin{:});
>>
That must be more recent than R2021b behavior...
Oh. I first missed that your example uses array2table() to pass an array, not the table(). A table itself as the input type is what isn't supported under a figure. The OP's example is all numeric data so it works as long as don't need to add other data types.
Ver también
Categorías
Más información sobre Develop uifigure-Based Apps en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!