Style Property Not Being Recognised

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 Comment

dpb
dpb on 28 Jun 2024
Edited: dpb on 29 Jun 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...

Sign in to comment.

Answers (2)

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 Comments

Scott Banks
Scott Banks on 29 Jun 2024
Edited: dpb on 29 Jun 2024
Sorry, I am not really following. Is there any other way to create borders, border colour etc for an ordinary, built in Matlab table?
dpb
dpb on 29 Jun 2024
Edited: dpb on 29 Jun 2024
No. The builtin table is not loaded down (thankfully) with all the overhead of the GUI stuff; it isn't intended to be a display object.
As Walter pointed out, you've left out the preliminaries and critical part of the example, the importation of the supporting report generator code and the creation of a Table() from it which is not at all the same thing as a builtin table()
I do not know, but I suspect one has to have a license to use Report Generator...let's see what happens here locally if...
>> import mlreportgen.dom.*;
rpt = Document('MyReport','html','MyTemplate');
table = Table(magic(5),'UnruledTable');
>> whos table
Name Size Bytes Class Attributes
table 1x1 8 mlreportgen.dom.Table
>> ver
-----------------------------------------------------------------------------------------------------
MATLAB Version: 9.11.0.2358333 (R2021b) Update 7
MATLAB License Number: xxxxxxxxxxxxxx
Operating System: Microsoft Windows 10 Pro Version 10.0 (Build 19045)
Java Version: Java 1.8.0_202-b08 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode
-----------------------------------------------------------------------------------------------------
MATLAB Version 9.11 (R2021b)
...
>>
Interesting...I guess it is available under the base MATLAB license; I was not aware of that. So, looks like if you follow the instructions/example as given you should be able to do so...I had always been under the impression it was a separately licensed toolbox.
Sorry, dpb, I don't mean to be stupid, but how would I include this in my original MATLAB code then?
dpb
dpb on 29 Jun 2024
Edited: dpb on 29 Jun 2024
Just as the example shows...copy and past the import line and define your table using the Table() function contained therein instead of with builtin table()
import mlreportgen.dom.*;
...
...
T=Table(Bracing_Unit1,Bracing_Unit2,Core_1,Core_2,'RowNames',Labels);
I'd personally put the import clear at the very beginning rather than burying it down somewhere in the bowels of the code, but it doesn't really matter other than before trying to refer to Table().
After that, I dunno what else you'll have to do but the style stuff and all should work on the Table in memory. How you get that to be visible or use it you'll have to follow the example and documentation; as noted, I've never used it. What can be done with it other than make printed reports as it appears the example is getting ready to do by the line
...
rpt = Document('MyReport','html','MyTemplate');
I don't know how rpt plays into things later not having read the example code nor whether you can somehow display it on screen or whatever as never used any of it; you'll have to read the documentation and see...I'm sure there's an introductory overview section there somewhere that will outline the general abilities.
The example that then uses table as the variable name is very poor practice and such should never show up in the official documentation. By using table as a variable name it has aliased the builtin table() function so one no longer could use one of those in your code as well--all the properties and methods for it will not be accessible. That would absolutely be mind-blowing to the inexperienced user...
From the local session I showed before, after running that code, then...
>> which -all table
table is a variable.
C:\MLR2021b\toolbox\matlab\bigdata\@tall\table.m % Shadowed tall method
C:\MLR2021b\toolbox\matlab\datatypes\tabular\@table\table.m % Shadowed table constructor
>>
you can see that the builtin table function is no longer available, all MATLAB will find will be a variable of type Table().
While we're at it, does it have its own builtin disp() or something to show up as fancy in the command window?
>> disp(table)
Table with properties:
ColSpecGroups: []
NCols: 5
NRows: 5
Width: []
HAlign: []
BackgroundColor: []
Border: []
BorderColor: []
BorderWidth: []
RowSep: []
RowSepColor: []
RowSepWidth: []
ColSep: []
ColSepColor: []
ColSepWidth: []
BorderCollapse: []
FlowDirection: []
OuterLeftMargin: []
TableEntriesStyle: []
TableEntriesVAlign: []
TableEntriesHAlign: []
TableEntriesInnerMargin: []
StyleName: 'UnruledTable'
Style: {1×0 cell}
CustomAttributes: []
Parent: []
Children: [1×5 mlreportgen.dom.TableRow]
Tag: 'dom.Table:6'
Id: '6'
>>
No, the command window "knows nuthink!" about how to display graphics...all that fancy display stuff has to be built on top of some graphics engine--whether it is a munged on handle graphics axis of some sort or built with some other graphics toolset is not visible/documented to the end user, but you see above where the properties you're trying to set are now available. Again, what else you will be able to do with it, I don't know. I suppose possibly it could go into a uifigure, maybe???
No, the above isn't supported and it appears rptview only supports the report you've generated so the above surmise about the function of rpt in the example is that displaying it is all you can do other than print the file...without importing the new Table(), you have nothing but an object in memory.
What I suspect you're actually looking for here may be the uitable graphics table instead...it has all 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.
Is there any other way to create borders, border colour etc for an ordinary, built in Matlab table?
No. table() objects are primarily for computation. The amount of customization you can do for the display of table() objects is very very limited.
dpb
dpb on 30 Jun 2024
Edited: dpb on 30 Jun 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?
Nope, format is about the limit.

Sign in to comment.

dpb
dpb on 29 Jun 2024
Edited: dpb on 29 Jun 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;
Error using matlab.internal.capability.Capability.require (line 94)
This functionality is not available on remote platforms.

Error in matlab.ui.internal.uifigureImpl (line 32)
Capability.require(Capability.WebWindow);

Error in uifigure (line 34)
window = matlab.ui.internal.uifigureImpl(varargin{:});
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 Comments

"... only can live in a uifigure"
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
dpb on 29 Jun 2024
Edited: dpb on 29 Jun 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.

Sign in to comment.

Categories

Asked:

on 28 Jun 2024

Commented:

on 30 Jun 2024

Community Treasure Hunt

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

Start Hunting!