How to Label Data Points in Matlab Plots

In Matlab, to label data points on a plot, you can use the plot function and achieve it by adding additional parameters.

For example, use the following code to create a simple scatter plot and label each data point:

% 创建随机数据
x = rand(1, 10);
y = rand(1, 10);

% 绘制散点图
scatter(x, y, 'filled');

% 标记数据点
hold on;
for i = 1:length(x)
    text(x(i), y(i), num2str(i), 'HorizontalAlignment', 'center', 'VerticalAlignment', 'bottom');
end
hold off;

In this example, we created a scatter plot with 10 random data points and used a for loop and the text function to label each data point with its corresponding number. By setting the HorizontalAlignment and VerticalAlignment parameters, you can adjust the positioning of the labels.

Additionally, symbols can be used as parameters in the plot function to label data points, for example:

x = 1:10;
y = rand(1, 10);

plot(x, y, 'o'); % 使用圆圈标记数据点
bannerAds