How can I split the graph into two parts?
13 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello everyone,
I have a matrix that I have created. I want to overlay these matrices on top of each other. However, I want to split the graph starting from the value x=3.89. The portion after 3.89 will be my main graph. I also want this graph to be scaled with the x-axis ranging from 0 to 1 in steps of 0.1 and the y-axis scaled as 10^{-6}×10−6. I would appreciate it if you could assist with this.
load('x_diff3.mat')
load('x_fdep3.mat')
figure;
plot( x_fdep, 'b'); % y-axis scaled by 10^-6
hold on;
plot(x_diff, 'r'); % y-axis scaled by 10^-6
xlabel('Time (s)');
ylabel('Particle Position (μm)'); % Units updated to micrometers
title('Particle Positions with and without DEP Force');
legend('DEP Force Present', 'Only Diffusion');
0 comentarios
Respuestas (1)
Shivam
el 4 de Sept. de 2024
Hi Haref,
Please refer to the following workaround to achieve the goal
load('x_diff3.mat');
load('x_fdep3.mat');
% Find the index corresponding to x = 3.89
% Generate x-values assuming they are linearly spaced
x_values = linspace(0, 1, length(x_fdep));
[~, idx] = min(abs(x_values - 3.89/10)); % Find the closest index to x = 3.89
% Extract the portion of the data starting from x = 3.89
x_fdep_main = x_fdep(idx:end);
x_diff_main = x_diff(idx:end);
% Adjust x-axis values for plotting
x_axis_scaled = linspace(0, 1, length(x_fdep_main));
% Scale the y-axis data
x_fdep_scaled = x_fdep_main * 1e-6;
x_diff_scaled = x_diff_main * 1e-6;
% Plot the data
figure;
plot(x_axis_scaled, x_fdep_scaled, 'b'); % DEP Force Present
hold on;
plot(x_axis_scaled, x_diff_scaled, 'r'); % Only Diffusion
% Customize the plot
xlabel('Scaled X-axis (0 to 1)');
ylabel('Particle Position (μm)');
title('Particle Positions with and without DEP Force');
legend('DEP Force Present', 'Only Diffusion');
axis([0 1 min([x_fdep_scaled; x_diff_scaled]) max([x_fdep_scaled; x_diff_scaled])]); % Adjust y-axis limits
grid on;
Let me know if you face any issues.
Regards
2 comentarios
Shivam
el 4 de Sept. de 2024
% Except second last time in previous script, set the axis limits
xlim([0 1]); % X-axis from 0 to 1
ylim([0 max([x_fdep_scaled; x_diff_scaled])]); % Y-axis starting from 0
grid on;
Ver también
Categorías
Más información sobre Specifying Target for Graphics Output 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!