Scatter data to smooth line plot

4 views (last 30 days)
Rohit
Rohit on 27 Aug 2024
Commented: Voss on 28 Aug 2024
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 Comment
Umar
Umar on 27 Aug 2024

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!

Sign in to comment.

Accepted Answer

Voss
Voss on 27 Aug 2024
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))

More Answers (1)

Umar
Umar on 27 Aug 2024

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!

Community Treasure Hunt

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

Start Hunting!