I want to make a table and have the results displayed in nice form
8 views (last 30 days)
Show older comments
I have the code in which I have found temperatures to corresponding nodes Now I want those displayed in form of good nice tables in command window when I run my code. Can anyone help it. The code is below just for understanding. JUST SEE THE LAST LINES NO NEED TO SEE THE FULL CODE JUST SEE THE LAST LINES AND PLEASE HELP HOW TO MAKE A TABLE
clc
clear
close all
format short g
L = 1; % Length in meters
Nodes = 5; % Cells or the control volumes We can control this (put whatever you want code is that flexible)
u = 2.5; % The velocity
rho = 1; % Density in kg/m^3
alpha = 0.1; % Diffusivity
dx = L/Nodes; % The distance between the centres of Control volumes or Cells
phi_A = 1; % Left Side Boundary Condition
phi_B = 0; % Right Side Boundary Condition
F = rho*u; % Fe = Fw as properties are constant everywhere
D = alpha/dx; % Dw = De as properties are same everywhere
S_u_1 = (2*D + F)*phi_A;
S_u_last = (2*D - F)*phi_B;
S_p_1 = -(2*D + F); % For node 1
S_p_last = -(2*D - F); % For last node
a_w_1 = 0; % For node 1
a_e_1 = D - F/2; % For node 2
a_w_last = D + F/2; % For last node
a_e_last = 0; % For last node
a_p_1 = a_w_1 + a_e_1 - S_p_1; % Central cefficent for Node 1
a_p_last = a_w_last + a_e_last - S_p_last; % Central Coefficent for last Node
a_w_internal = D + F/2; % West side coefficent for internal Nodes
a_e_internal = D - F/2; % East Side coefficent for internal Nodes
a_p_internal = a_w_internal + a_e_internal;
% Now Using the Loops and If Conditionals for Populating the Coefficent and Right Side Matrix we have
A = zeros(Nodes);
B = zeros(1,Nodes)';
for i = 1:Nodes
for j = 1: Nodes
if ( i==j && i == 1)
A(i,j) = - a_p_1;
elseif (i==j && i == Nodes)
A(i,j) = - a_p_last;
elseif (i == j && i ~= 1 && i ~= Nodes)
A(i,j) = - a_p_internal;
elseif ( i>j )
A(i,i-1) = a_w_internal;
elseif ( i<j )
A(i,i+1) = a_e_internal;
end
end
if ( i == 1 )
B(i) = -S_u_1;
elseif (i == Nodes)
B(i) = -S_u_last;
end
end
phi = A\B;
phi = [phi_A,phi',phi_B]; % Finite Volume Method Solution Vector
Func = @(x) (exp(rho*u*x/alpha) - 1)./(exp(rho*u*L/alpha) - 1) .* (phi_B - phi_A) + phi_A;
% Analytical Solution valid for any Boundary Condition
Ana_vect = linspace(0,L,200);
Analytical_Sol = Func(Ana_vect);
vect = [0,dx/2,dx+dx/2:dx:L-dx/2,L]; % The vector depending upon the Nodes
figure(3),clf
hold on
plot(vect,phi,'k^',vect,phi,'r','linew',1.2,'markersize',8,'markerfacecolor','k')
plot(Ana_vect,Analytical_Sol,'b--','linew',1.2)
xlabel('Nodal Points (m)')
ylabel('Phi (Flux)')
title('Temperature vs Length')
% Use this to control x and y axis ticks
% xticks(vect)
% yticks(min(Analytical_Sol):100:max(Analytical_Sol))
legend('Finite Volume Solution','','Analytical Solution','location','NorthEast')
grid on
Tab = table(vect,phi);
disp(Tab)
The VARIABLE VECT CONTAINS ALL THE NODE POINTS AND PHI VECTOR ARE TEH CORRESPONIDNG PROPERTIES I WANT TO MAKE TABLE OF COLUMNS SIDE BY SIDE FOR NICE PRESENTATION.
ANY HELP WOULD BE APPRECIATED
1 Comment
dpb
on 13 Apr 2022
The table object does a nice job of presenting its results visually in the command window -- read the doc and see the examples for putting various variables into a table; all you have to do is define which variables you want to use.
Answers (0)
See Also
Categories
Find more on Lighting, Transparency, and Shading in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!