# Plotting of colormap for single value in x axis and multiple values in y axis

조회 수: 2 (최근 30일)
Joydeep Bagchi 2023년 9월 29일
댓글: Voss 2023년 10월 1일
% 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없음 표시없음 숨기기
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.
Joydeep Bagchi 2023년 9월 29일
Actually I cannot share the whole code due to some other issues
It is just the plotting of u(thickness, timestep) which is storing the temperature values
so I want to see the temperature distribution only at 8.49 seconds and the axis limits should be short

댓글을 달려면 로그인하십시오.

### 채택된 답변

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이전 댓글 4개 표시이전 댓글 4개 숨기기
Joydeep Bagchi 2023년 10월 1일
i just have shifted the axis and in the color bar i have choosen the values to be integer
Voss 2023년 10월 1일
Is that the desired result? If not, what is?
Are we making progress here?

댓글을 달려면 로그인하십시오.

### 추가 답변 (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
##### 댓글 수: 3이전 댓글 1개 표시이전 댓글 1개 숨기기
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
absorption = 50; % in %
performance = 80; % in %
%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')
Joydeep Bagchi 2023년 9월 30일
Ok, thankyou torsten for your reply but I have implemented other option

댓글을 달려면 로그인하십시오.

### 카테고리

Help CenterFile Exchange에서 Vector Fields에 대해 자세히 알아보기

R2023a

### Community Treasure Hunt

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

Start Hunting!

Translated by