How to change my y-axis?
11 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
cindyawati cindyawati
el 24 de En. de 2025
Comentada: Ishaan
el 28 de En. de 2025
I want to change my y-axis so in the below from 0 to 100, and why my result give me the square (like grid) in the middle

5 comentarios
Voss
el 27 de En. de 2025
% Hyperthermia Simulation with an Improved Biological Model
clear; clc; close all;
%% Parameter Model
alpha = 0.5; % thermal conductivity (cm^2/s)
Q = 0.1; % hot source (W/cm^3)
r0 = 0.03; % cancer growth (1/s)
beta = 0.02; % temperature sensitivity
Topt = 37; % temperarature for cancer growth (Celsius)
K = 1e6; % capacity of cancer
N0 = 1e4; % amount of cancer at the begining
omega_b = 0.01; % blood cooling (1/s)
T_blood = 37; % temperatur of blood (Celsius)
death_threshold = 45; % the boundary temperature above which cells die(Celsius)
death_rate = 0.05; % The rate of cell death if the temperature is too high
time = 0:0.1:100; % time simulation(second)
x = 0:0.1:5; % spatial position (cm)
[X, T] = meshgrid(x, time); % grid 2D
%% Temperature Initialization
T_t = zeros(length(time), length(x)); % temperature at t
T_t(:, 1) = T_blood; % temperature initial
%% Iteration Time for Temperature Distribution
for t = 2:length(time)
for i = 2:length(x)-1
% Equation of heat with cooling of blood
T_t(t, i) = T_t(t-1, i) + alpha * (T_t(t-1, i+1) - 2 * T_t(t-1, i) + T_t(t-1, i-1)) ...
- omega_b * (T_t(t-1, i) - T_blood) + Q;
end
% Set boundary conditions
T_t(t, 1) = T_t(t, 2); % limit left
T_t(t, end) = T_t(t, end-1); % limit right
end
%% Tumor Growth Model
N = zeros(length(time), 1); % Number of tumor cells
N(1) = N0; % Initial cell number
for t = 2:length(time)
% Tissue center temperature
T_mid = T_t(t, ceil(length(x)/2));
% Correction of tumor growth rate with temperature
r_t = r0 * exp(-beta * (T_mid - Topt)^2);
% If the temperature exceeds the threshold for cell death
if T_mid > death_threshold
r_t = r_t - death_rate;
end
% Tumor cell growth model
N(t) = N(t-1) + r_t * N(t-1) * (1 - N(t-1)/K);
end
%% Plot result
figure;
% temperature distribution
subplot(1, 2, 1);
imagesc(x, time, T_t);
set(gca, 'YDir', 'normal');
xlabel('Position (cm)');
ylabel('Time (s)');
title('Temperature Distribution in Tissue');
colorbar;
caxis([T_blood 45]); % Range temperature
%colormap('hot');
% cancer growth
subplot(1, 2, 2);
plot(time, N, 'LineWidth', 2);
xlabel('Time (s)');
ylabel('Number of Tumor Cells');
title('Tumor Growth vs Time');
%grid on;
%% result
fprintf('Simulasi selesai. \n');
fprintf('Jumlah sel tumor awal: %.2f\n', N0);
fprintf('Jumlah sel tumor akhir: %.2f\n', N(end));
fprintf('Suhu akhir di tengah jaringan: %.2f °C\n', T_t(end, ceil(length(x)/2)));
Respuesta aceptada
Malay Agarwal
el 27 de En. de 2025
Editada: Malay Agarwal
el 27 de En. de 2025
To reverse the direction of the y-axis, you can use the following command:
set(gca, 'YDir', 'normal');
By default, the imagesc function changes the y-axis direction to "reverse", which is why 0 is at the top and 100 is at the bottom. The above command changes the direction back to "normal". I have attached your code with this modification. Here is the result:
tmp
Refer to the following answer from MathWorks Support team for more details: https://www.mathworks.com/matlabcentral/answers/94170-how-can-i-reverse-the-y-axis-when-i-use-the-image-or-imagesc-function-to-display-an-image-in-matlab
Hope this helps!
3 comentarios
Malay Agarwal
el 27 de En. de 2025
You can call the command again for the second plot and it should reverse that as well.
Voss
el 27 de En. de 2025
Or just avoid calling
set(gca, 'YDir', 'reverse');
on the second subplot.
Más respuestas (1)
Ishaan
el 28 de En. de 2025
I understand that you intend to flip the y-axis ticks and fix the grid like pattern towards the (current) bottom of the plot. To reproduce the plot, I isolated the code snippet that generated the figure you provided.
alpha = 0.5; % thermal conductivity (cm^2/s)
Q = 0.1; % hot source (W/cm^3)
omega_b = 0.01; % blood cooling (1/s)
T_blood = 37; % temperatur of blood (Celsius)
time = 0:0.1:100; % time simulation(second)
x = 0:0.1:5; % spatial position (cm)
%% Temperature Initialization
T_t = zeros(length(time), length(x)); % temperature at t
T_t(:, 1) = T_blood; % temperature initial
%% Iteration Time for Temperature Distribution
for t = 2:length(time)
for i = 2:length(x)-1
% Equation of heat with cooling of blood
T_t(t, i) = T_t(t-1, i) + alpha * (T_t(t-1, i+1) - 2 * T_t(t-1, i) + T_t(t-1, i-1)) ...
- omega_b * (T_t(t-1, i) - T_blood) + Q;
end
% Set boundary conditions
T_t(t, 1) = T_t(t, 2); % limit left
T_t(t, end) = T_t(t, end-1); % limit right
end
imagesc(x, time, T_t);
colorbar;
caxis([T_blood 45]); % Range temperature
Firstly, to change your y-axis order, you can flip the time variable like this.
time = 100:-0.1:0;
NOTE: This will flip the plot generated as well.
Alternatively, you can use the other methods mentioned to flip the y-axis.
Upon inspecting the image ”matrix (T_t)”, near the square (like grid) I notice that adjacent values have large differences.
T_t(970:979, 18:24)

This is leading to the grid like output. I also noticed that the top row of `T_t` is initialized to 0 and is never modified in the loop.
Hence, you will need to cross-check the equation of heat with cooling of blood as that is generating the “T_t” matrix.
2 comentarios
Ishaan
el 28 de En. de 2025
I suggest you to check some sections of the "T_t" matrix and verify if the values are as you expect. As the graph is plotted according to the matrix data.
To clarify, "T_t(412:414, 9:11)" is:

Notice that there is very less difference in adjacent values. This is the yellow area of the graph.
For the values in the bell bottom, the difference between adjacent values is large, "99.2591" and "-4.8532". Hence the grid like pattern of alternate blue and yellow values.
Ver también
Categorías
Más información sobre Biological and Health Sciences en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!