Scatter data to smooth line plot

4 次查看(过去 30 天)
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))

更多回答(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