How can I split the graph into two parts?

조회 수: 14 (최근 30일)
Zaref Li
Zaref Li 2024년 9월 4일
편집: Voss 2024년 9월 4일
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}×106. 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');

답변 (1개)

Shivam
Shivam 2024년 9월 4일
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
Zaref Li
Zaref Li 2024년 9월 4일
Can we also start the y-axis from 0? Thank you.
Shivam
Shivam 2024년 9월 4일
% 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;

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

카테고리

Help CenterFile Exchange에서 Specifying Target for Graphics Output에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by