Plot two points on single x value

조회 수: 3 (최근 30일)
Jihun Gil
Jihun Gil 2021년 8월 15일
편집: Vedant Shah 2025년 2월 4일
Hi, I need to plot a scatter graph (x,y) that has multiple y values on single x.
for example, x y
1 1
2 2
3 1,3
4 2,4
5 5
I have no idea with plotting double points in x=3,4 . How can I plot (x,y)?? please help

답변 (1개)

Vedant Shah
Vedant Shah 2025년 2월 4일
편집: Vedant Shah 2025년 2월 4일
To plot a scatter graph for data where there might be multiple y-values corresponding to a single x-value, the following code can be referred:
% Data
x = [1, 2, 3, 3, 4, 4, 5];
y = [1, 2, 1, 3, 2, 4, 5];
% Create scatter plot
scatter(x, y, 'filled');
% Add labels and title
xlabel('x');
ylabel('y');
title('Scatter Plot');
In this example, I have created two row vectors: one for the x-values and another for the y-values. The x-values are repeated where there are multiple corresponding y-values.
The resulting plot is as desired and can be seen below:
For more information, you can refer to the following documentations:

카테고리

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