Plotting of colormap for single value in x axis and multiple values in y axis
1 回表示 (過去 30 日間)
古いコメントを表示
% Choose the time you want to visualize
desired_time = 2.5; % Change this to the desired time in seconds
% Find the nearest time step to the desired time
[~, time_step_to_visualize] = min(abs(t - desired_time));
% Plot the temperature distribution as a color spectrum
figure;
imagesc(t(time_step_to_visualize), y, u(:, time_step_to_visualize));
colormap(jet);
% Get the temperature values at the specified time step
temperature_values = u(:, time_step_to_visualize);
% Set color axis limits to match the temperature variation at the specified time step
clim([min(temperature_values(:)), max(temperature_values(:))]);
% Create a color bar and adjust its position and size
colorbar;
xlabel('Time (seconds)');
ylabel('Thickness (meters)');
title(['Temperature Distribution at Time = ', num2str(t(time_step_to_visualize)), ' seconds']);
% Set axis limits
xlim([t(time_step_to_visualize-1), t(time_step_to_visualize)]);
ylim([0, max(y)]);
% Invert the y-axis direction
set(gca, 'YDir', 'normal');
I have tried to plot the color map of temperature at t=''secs but I am getting the temperature distribution over the whole axis limit. Could someone please tell me how to change the code for temperature distribution only at time step t?
2 件のコメント
Constantino Carlos Reyes-Aldasoro
2023 年 9 月 29 日
This is not completely clear. We cannot reproduce the code as we do not have time, nor we can see what exactly is the problem. Add figures to illustrate what you get and what you would like to have.
採用された回答
Voss
2023 年 9 月 29 日
Something like this? The only change is to set xlim(t([1 end])), i.e., let the x-limits span the entire t vector.
t = 0:10;
y = 0:5;
u = rand(6,11);
% Choose the time you want to visualize
desired_time = 2.5; % Change this to the desired time in seconds
% Find the nearest time step to the desired time
[~, time_step_to_visualize] = min(abs(t - desired_time));
% Plot the temperature distribution as a color spectrum
figure;
imagesc(t(time_step_to_visualize), y, u(:, time_step_to_visualize));
colormap(jet);
% Get the temperature values at the specified time step
temperature_values = u(:, time_step_to_visualize);
% Set color axis limits to match the temperature variation at the specified time step
clim([min(temperature_values(:)), max(temperature_values(:))]);
% Create a color bar and adjust its position and size
colorbar;
xlabel('Time (seconds)');
ylabel('Thickness (meters)');
title(['Temperature Distribution at Time = ', num2str(t(time_step_to_visualize)), ' seconds']);
% Set axis limits
% xlim([t(time_step_to_visualize-1), t(time_step_to_visualize)]);
xlim(t([1 end]));
ylim([0, max(y)]);
% Invert the y-axis direction
set(gca, 'YDir', 'normal');
6 件のコメント
その他の回答 (1 件)
Torsten
2023 年 9 月 29 日
移動済み: Torsten
2023 年 9 月 29 日
Use a contour plot
with time and thickness as axes and temperature for color.
To do this, add the lines
contourf(t,y,u)
colorbar
to your code under
3 件のコメント
Torsten
2023 年 9 月 29 日
編集済み: Torsten
2023 年 9 月 29 日
If you want a plot of the temperature distribution over the web at a specific time, you should use plot(y,T(t)). Everything else would be confusing in my opinion:
% Constants
Ly = 0.001; % Thickness of the sheet (meters)
T = 15; % Total simulation time (seconds)
Ny = 20; % Number of spatial grid points
Nt = 3000; % Number of time steps
k1 = 0.15; % Thermal conductivity of PVC W/m-K
rho = 1250; % density in kg/m3
cp = 1350 ; % specific heat in J/kg-K
alpha = k1/(rho*cp); % Thermal diffusivity (m^2/s)
T_ambient = 25; % Ambient temperature (°C)
velocity_x = 0.1667; % Velocity in x-direction (m/s)
%contact with hot roller
k2 = 50; %Thermal conductivity of steel roller W/m-K
h_roller = 500; %convective heat transfer coefficient of roller W/m2-K
d_roller = 0.4; %diameter of roller in m
contact_angle = 180; %in °
contact_length = pi*d_roller*contact_angle/360; %contact length with roller
T_roller = 100; % Roller temperature
%Contact in air
distance_x = 0.5; % Distance traveled in x-direction (meters)
h_air = 12; % Convective heat transfer coefficient of air W/m2-K
%Contact in IR field
distance_ir = 0.3 ; % in m
radiative_flux = 50e3; %W/m2
absorption = 50; % in %
performance = 80; % in %
Net_radiative_intensity = radiative_flux*(absorption/100)*(performance/100);
%Contact with air again
distance_v = 1 ; % in m
%Naming the distance variables
y1 = contact_length;
y2 = contact_length + distance_x;
y3 = contact_length + distance_x+ distance_ir;
y4 = contact_length + distance_x+ distance_ir+distance_v;
% Discretization
dy = Ly / (Ny - 1);
dt = T / Nt;
y = linspace(0, Ly, Ny);
t = linspace(0, T, Nt);
% Initial temperature distribution
initial_temperature = 25;
distance_travelled = zeros(1,Nt); %initial distance travelled
% Initialize temperature matrix
u = zeros(Ny, Nt);
u(:, 1) = initial_temperature;
% Forward euler method
r = alpha * dt / (dy^2); % as 0 < r < 0.5
% Time-stepping loop (explicit method)
for n = 1:Nt - 1
% Update position in x-direction
distance_travelled(n+1) = distance_travelled(n) + velocity_x * dt;
% Check if the total distance is within the contact length
if distance_travelled(n) <= y1
for i = 2:Ny - 1
u(i, n + 1) = u(i, n) + r * (u(i + 1, n) - 2 * u(i, n) + u(i - 1, n));
end
% Apply boundary conditions for contact with the roller
%u(1, n + 1) = ((h_roller * T_roller * dy) + (k1 * u(2, n))) / (k1 + h_roller * dy);
%u(Ny, n + 1) = ((h_air * T_ambient * dy) + (k1 * u(Ny - 1, n))) / (k1 + h_air * dy);
u(1, n + 1) = u(1,n) + dt*(alpha*(u(2,n)-u(1,n))/dy - h_roller/(rho*cp)*(u(1,n)-T_roller))/(dy/2);
u(Ny, n + 1) = u(Ny,n) + dt*(-h_air/(rho*cp)*(u(Ny, n)-T_ambient)-alpha*(u(Ny,n)-u(Ny-1,n))/dy)/(dy/2);
% For the next part in contact with air
elseif distance_travelled(n) <= y2
for i = 2:Ny - 1
u(i, n + 1) = u(i, n) + r * (u(i + 1, n) - 2 * u(i, n) + u(i - 1, n));
end
% Apply boundary conditions for contact with air
%u(1, n + 1) = ((h_air * T_ambient * dy) + (k1 * u(2, n + 1))) / (k1 + h_air * dy);
%u(Ny, n + 1) = ((h_air * T_ambient * dy) + (k1 * u(Ny - 1, n + 1))) / (k1 + h_air * dy);
u(1, n + 1) = u(1,n) + dt*(alpha*(u(2,n)-u(1,n))/dy - h_air/(rho*cp)*(u(1,n)-T_ambient))/(dy/2);
u(Ny, n + 1) = u(Ny,n) + dt*(-h_air/(rho*cp)*(u(Ny, n)-T_ambient)-alpha*(u(Ny,n)-u(Ny-1,n))/dy)/(dy/2);
%In contact with IR field radiation
elseif distance_travelled(n) <= y3
for i = 2:Ny - 1
u(i, n + 1) = u(i, n) + r * (u(i + 1, n) - 2 * u(i, n) + u(i - 1, n));
end
% Apply boundary conditions for contact with IR field
%u(1, n + 1) = ((h_air * T_ambient * dy) + (k1 * u(2, n + 1))) / (k1 + h_air * dy);
%u(Ny, n + 1) = u(Ny - 1, n + 1) + ((Net_radiative_intensity * dy) / k1);
u(1, n + 1) = u(1,n) + dt*(alpha*(u(2,n)-u(1,n))/dy - h_air/(rho*cp)*(u(1,n)-T_ambient))/(dy/2);
u(Ny, n + 1) = u(Ny,n) + dt*(Net_radiative_intensity/(rho*cp)-alpha*(u(Ny,n)-u(Ny-1,n))/dy)/(dy/2);
% Distance in contact with air again
else
for i = 2:Ny - 1
u(i, n + 1) = u(i, n) + r * (u(i + 1, n) - 2 * u(i, n) + u(i - 1, n));
end
% Apply boundary conditions for contact with air
%u(1, n + 1) = ((h_air * T_ambient * dy) + (k1 * u(2, n + 1))) / (k1 + h_air * dy);
%u(Ny, n + 1) = ((h_air * T_ambient * dy) + (k1 * u(Ny - 1, n + 1))) / (k1 + h_air * dy);
u(1, n + 1) = u(1,n) + dt*(alpha*(u(2,n)-u(1,n))/dy - h_air/(rho*cp)*(u(1,n)-T_ambient))/(dy/2);
u(Ny, n + 1) = u(Ny,n) + dt*(-h_air/(rho*cp)*(u(Ny, n)-T_ambient)-alpha*(u(Ny,n)-u(Ny-1,n))/dy)/(dy/2);
end
% Break the loop when the total distance is reached
if distance_travelled(n + 1) >= y4
break;
end
end
for i = 1:numel(y)
tempcut(i) = interp1(t,u(i,:),8.49);
end
plot(y,tempcut)
xlabel('Thickness [m]')
ylabel('Temperature [°C]')
title('Temperature Distribution at Time = 8.49 s')
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!