How can I put an output from the display function in a table?

5 views (last 30 days)
Hi there,
I am wondering how I can put the results using the display function into a table.
This is the code:
Section = ['254 x 254 x 73';'254 x 146 x 31';'254 x 146 x 31';'254 x 254 x 73';'254 x 254 x 73';'152 x 152 x 51';'152 x 152 x 51';'152 x 152 x 51';'203 x 203 x 46';'203 x 203 x 52'];
h = [254.1; 251.4; 251.4; 254.1; 254.1; 170.2; 170.2; 170.2; 203.2; 206.2];
b = [254.6; 146.1; 146.1; 254.6; 254.6; 157.4; 157.4; 157.4; 203.6; 204.3];
tw = [8.6; 6.00; 6.00; 8.6; 8.6; 11.00; 11.00; 11.00; 7.2; 7.9];
tf = [14.2; 8.6; 8.6; 14.2; 14.2; 15.7; 15.7; 15.7; 11.00; 12.5];
r = [12.7; 7.6; 7.6; 12.7; 12.7; 7.6; 7.6; 7.6; 10.2; 10.2];
E = 0.81;
for i = 1:length(h)
Cw(i) = h(i) - 2*(tf(i)) - 2*(r(i));
c_w(i) = Cw(i)/(tw(i));
if c_w(i) < 72*E
disp("Web is class 1")
else
disp("Web is not class 1")
end
Cf(i) = b(i)/2 - tw(i)/2 - r(i);
c_f(i) = Cf(i)/tf(i);
if c_f(i) < 9*E
disp("Flange is class 1")
elseif c_f(i) < 10*E
disp("Flange is class 2")
else
disp("Section is Class 3 or 4")
end
end
I would like to have a table with the 'sections' displaying "Web is class 1" or "Flange is class 2". MATLAB doesn't seem to let me assign a variable to the display function, so I can't work out how to put the data into a table.
Can someone help please?

Answers (2)

Fangjun Jiang
Fangjun Jiang on 25 Mar 2024
Create a table, fill the data and display it.
doc table

VBBV
VBBV on 25 Mar 2024
Edited: VBBV on 25 Mar 2024
Section = ['254 x 254 x 73';'254 x 146 x 31';'254 x 146 x 31';'254 x 254 x 73';'254 x 254 x 73';'152 x 152 x 51';'152 x 152 x 51';'152 x 152 x 51';'203 x 203 x 46';'203 x 203 x 52'];
h = [254.1; 251.4; 251.4; 254.1; 254.1; 170.2; 170.2; 170.2; 203.2; 206.2];
b = [254.6; 146.1; 146.1; 254.6; 254.6; 157.4; 157.4; 157.4; 203.6; 204.3];
tw = [8.6; 6.00; 6.00; 8.6; 8.6; 11.00; 11.00; 11.00; 7.2; 7.9];
tf = [14.2; 8.6; 8.6; 14.2; 14.2; 15.7; 15.7; 15.7; 11.00; 12.5];
r = [12.7; 7.6; 7.6; 12.7; 12.7; 7.6; 7.6; 7.6; 10.2; 10.2];
E = 0.81;
for i = 1:length(h)
Cw(i) = h(i) - 2*(tf(i)) - 2*(r(i));
c_w(i) = Cw(i)/(tw(i));
if c_w(i) < 72*E
T1{i} = "Web is class 1";
else
T1{i} = "Web is not class 1";
end
Cf(i) = b(i)/2 - tw(i)/2 - r(i);
c_f(i) = Cf(i)/tf(i);
if c_f(i) < 9*E
T2{i} = "Flange is class 1";
elseif c_f(i) < 10*E
T2{i} = "Flange is class 2";
else
T2{i} = "Section is Class 3 or 4";
end
end
Table = table(c_w.',c_f.',T1.',T2.');
disp(Table)
Var1 Var2 Var3 Var4 ______ ______ ____________________ _______________________ 23.291 7.7676 {["Web is class 1"]} {["Flange is class 2"]} 36.5 7.2616 {["Web is class 1"]} {["Flange is class 1"]} 36.5 7.2616 {["Web is class 1"]} {["Flange is class 1"]} 23.291 7.7676 {["Web is class 1"]} {["Flange is class 2"]} 23.291 7.7676 {["Web is class 1"]} {["Flange is class 2"]} 11.236 4.1783 {["Web is class 1"]} {["Flange is class 1"]} 11.236 4.1783 {["Web is class 1"]} {["Flange is class 1"]} 11.236 4.1783 {["Web is class 1"]} {["Flange is class 1"]} 22.333 8 {["Web is class 1"]} {["Flange is class 2"]} 20.354 7.04 {["Web is class 1"]} {["Flange is class 1"]}
  4 Comments
VBBV
VBBV on 27 Mar 2024
Edited: VBBV on 27 Mar 2024
@Scott BanksAn alternative to disp and table functions is using fprintf function as below
Section = ['254 x 254 x 73';'254 x 146 x 31';'254 x 146 x 31';'254 x 254 x 73';'254 x 254 x 73';'152 x 152 x 51';'152 x 152 x 51';'152 x 152 x 51';'203 x 203 x 46';'203 x 203 x 52'];
h = [254.1; 251.4; 251.4; 254.1; 254.1; 170.2; 170.2; 170.2; 203.2; 206.2];
b = [254.6; 146.1; 146.1; 254.6; 254.6; 157.4; 157.4; 157.4; 203.6; 204.3];
tw = [8.6; 6.00; 6.00; 8.6; 8.6; 11.00; 11.00; 11.00; 7.2; 7.9];
tf = [14.2; 8.6; 8.6; 14.2; 14.2; 15.7; 15.7; 15.7; 11.00; 12.5];
r = [12.7; 7.6; 7.6; 12.7; 12.7; 7.6; 7.6; 7.6; 10.2; 10.2];
E = 0.81;
for i = 1:length(h)
Cw(i) = h(i) - 2*(tf(i)) - 2*(r(i));
c_w(i) = Cw(i)/(tw(i));
if c_w(i) < 72*E
T1{i} = "Web is class 1";
fprintf(' ')
fprintf('\nc_w section')
fprintf('------------------------------------')
fprintf('%2.2d\t %s\n',c_w(i),T1{i})
else
T1{i} = "Web is not class 1";
fprintf('%2.2d\t %s\n',c_w(i),T1{i})
end
Cf(i) = b(i)/2 - tw(i)/2 - r(i);
c_f(i) = Cf(i)/tf(i);
if c_f(i) < 9*E
T2{i} = "Flange is class 1";
fprintf(' ')
fprintf('\nc_f section')
fprintf('-----------------------------------')
fprintf('%2.2d\t %s\n',c_f(i),T2{i})
elseif c_f(i) < 10*E
T2{i} = "Flange is class 2";
fprintf('%2.2d\t %s\n',c_f(i),T2{i})
else
T2{i} = "Section is Class 3 or 4";
fprintf('%2.2d\t %s\n',c_f(i),T2{i})
end
end
c_w section
------------------------------------
2.33e+01 Web is class 1
7.77e+00 Flange is class 2
c_w section
------------------------------------
3.65e+01 Web is class 1
c_f section
-----------------------------------
7.26e+00 Flange is class 1
c_w section
------------------------------------
3.65e+01 Web is class 1
c_f section
-----------------------------------
7.26e+00 Flange is class 1
c_w section
------------------------------------
2.33e+01 Web is class 1
7.77e+00 Flange is class 2
c_w section
------------------------------------
2.33e+01 Web is class 1
7.77e+00 Flange is class 2
c_w section
------------------------------------
1.12e+01 Web is class 1
c_f section
-----------------------------------
4.18e+00 Flange is class 1
c_w section
------------------------------------
1.12e+01 Web is class 1
c_f section
-----------------------------------
4.18e+00 Flange is class 1
c_w section
------------------------------------
1.12e+01 Web is class 1
c_f section
-----------------------------------
4.18e+00 Flange is class 1
c_w section
------------------------------------
2.23e+01 Web is class 1
08 Flange is class 2
c_w section
------------------------------------
2.04e+01 Web is class 1
c_f section
-----------------------------------
7.04e+00 Flange is class 1
% Table = table(c_w.',c_f.',T1.',T2.');
% disp(Table)

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!