0
0
MATLABdata~5 mins

Scatter plots in MATLAB

Choose your learning style9 modes available
Introduction

Scatter plots help you see how two sets of numbers relate to each other. They show points on a graph so you can spot patterns or trends.

To check if there is a relationship between hours studied and exam scores.
To see how temperature changes with time during a day.
To compare sales numbers of two products over several months.
To find out if taller people tend to weigh more.
To explore if advertising budget affects the number of customers.
Syntax
MATLAB
scatter(x, y)
scatter(x, y, size)
scatter(x, y, size, color)
scatter(x, y, size, color, 'filled')

x and y are vectors of the same length representing points.

You can change the size and color of points to add more information.

Examples
Basic scatter plot with points at (x, y).
MATLAB
x = [1 2 3 4 5];
y = [2 4 1 3 5];
scatter(x, y)
Scatter plot with larger points (size 100).
MATLAB
x = rand(1,10);
y = rand(1,10);
scatter(x, y, 100)
Scatter plot with colored and filled points.
MATLAB
x = 1:5;
y = [5 3 6 2 7];
colors = [10 20 30 40 50];
scatter(x, y, 100, colors, 'filled')
Sample Program

This program plots prime numbers (y) against their position (x). Points are red and filled for clear visibility.

MATLAB
x = [1 2 3 4 5 6 7 8 9 10];
y = [2 3 5 7 11 13 17 19 23 29];
scatter(x, y, 100, 'r', 'filled')
title('Scatter plot of x vs y')
xlabel('x values')
ylabel('y values')
OutputSuccess
Important Notes

Use hold on to add multiple scatter plots on the same figure.

Use colorbar to show what colors mean if you use color to represent data.

Always label your axes and add a title for clarity.

Summary

Scatter plots show points to explore relationships between two variables.

You can customize point size and color to add more meaning.

Label your plot to make it easy to understand.