Scatter data to smooth line plot

조회 수: 8 (최근 30일)
Rohit
Rohit 2024년 8월 27일
댓글: Voss 2024년 8월 28일
I have a scattered data (Attached file). By using a scatter command it give me a circular form. I want to join the data point of circle by line. How can we do this? Please give idea.
  댓글 수: 1
Umar
Umar 2024년 8월 27일

Hi @Rohit,

To address your query regarding, “I have a scattered data (Attached file). By using a scatter command it give me a circular form. I want to join the data point of circle by line. How can we do this? Please give idea.”

Please see my response to your comments below.

Since Pos_UI1 is a matrix with two columns (assuming the first column represents the x-coordinates and the second column represents the y-coordinates), I extracted these coordinates for plotting. Then, used the scatter function to visualize the individual points. Afterwards, plot function to connect the points in the order they are arranged in the matrix. Here is a complete example based on your provided code:

% Load the variables into the workspace
data = load('U_Au_T100.mat');
% Display the contents of the loaded data
disp(data);
% Extract the position data
Pos_UI1 = data.Pos_UI1; % Assuming Pos_UI1 is the variable name
% Extract x and y coordinates
x = Pos_UI1(:, 1); % First column for x-coordinates
y = Pos_UI1(:, 2); % Second column for y-coordinates
% Create a scatter plot of the data points
figure; % Create a new figure window
scatter(x, y, 'filled', 'MarkerFaceColor', 'b'); % Scatter plot with blue filled 
circles
hold on; % Hold the current plot
% Connect the data points with lines
plot(x, y, 'r-', 'LineWidth', 1.5); % Plot lines connecting the points in red
% Add labels and title
xlabel('X Coordinate');
ylabel('Y Coordinate');
title('Scatter Plot with Connected Lines');
grid on; % Add a grid for better visualization
hold off; % Release the hold on the current plot

Please see attached.

If you have any further questions or need additional assistance, feel free to ask!

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

채택된 답변

Voss
Voss 2024년 8월 27일
load U_Au_T100
XY = Pos_UI1;
scatter(XY(:,1),XY(:,2))
C = mean(XY,1);
XY0 = XY-C;
th = atan2(XY0(:,2),XY0(:,1));
[~,idx] = sort(th);
idx(end+1) = idx(1);
hold on
plot(XY(idx,1),XY(idx,2))
  댓글 수: 2
Rohit
Rohit 2024년 8월 28일
Thank you Voss. It works.
Voss
Voss 2024년 8월 28일
You're welcome!

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

추가 답변 (1개)

Umar
Umar 2024년 8월 27일

Hi @Rohit,

To address your query regarding, “I have a scattered data (Attached file). By using a scatter command it give me a circular form. I want to join the data point of circle by line. How can we do this? Please give idea.”

Please see my response to your comments below.

Since Pos_UI1 is a matrix with two columns (assuming the first column represents the x-coordinates and the second column represents the y-coordinates), I extracted these coordinates for plotting. Then, used the scatter function to visualize the individual points. Afterwards, plot function to connect the points in the order they are arranged in the matrix. Here is a complete example based on your provided code:

% Load the variables into the workspace
data = load('U_Au_T100.mat');
% Display the contents of the loaded data
disp(data);
% Extract the position data
Pos_UI1 = data.Pos_UI1; % Assuming Pos_UI1 is the variable name
% Extract x and y coordinates
x = Pos_UI1(:, 1); % First column for x-coordinates
y = Pos_UI1(:, 2); % Second column for y-coordinates
% Create a scatter plot of the data points
figure; % Create a new figure window
scatter(x, y, 'filled', 'MarkerFaceColor', 'b'); % Scatter plot with blue filled 
circles
hold on; % Hold the current plot
% Connect the data points with lines
plot(x, y, 'r-', 'LineWidth', 1.5); % Plot lines connecting the points in red
% Add labels and title
xlabel('X Coordinate');
ylabel('Y Coordinate');
title('Scatter Plot with Connected Lines');
grid on; % Add a grid for better visualization
hold off; % Release the hold on the current plot

Please see attached.

If you have any further questions or need additional assistance, feel free to ask!

카테고리

Help CenterFile Exchange에서 Scatter Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by