Scatter data to smooth line plot

4 visualizaciones (últimos 30 días)
Rohit
Rohit el 27 de Ag. de 2024
Comentada: Voss el 28 de Ag. de 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 comentario
Umar
Umar el 27 de Ag. de 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!

Iniciar sesión para comentar.

Respuesta aceptada

Voss
Voss el 27 de Ag. de 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))
  2 comentarios
Rohit
Rohit el 28 de Ag. de 2024
Thank you Voss. It works.
Voss
Voss el 28 de Ag. de 2024
You're welcome!

Iniciar sesión para comentar.

Más respuestas (1)

Umar
Umar el 27 de Ag. de 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!

Categorías

Más información sobre Scatter Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by