图中的文本或注释

Text or annotation in a plot

因为我不明白符号是如何工作的,所以我只需要在图中添加平均值并添加标签来写点。我加了白星

scatter(azimuth,elevation,'r'),'filled';
hold on;
plot(az_mean,el_mean,'wp'); hold on;

然后我用

添加了标签
str = {az1_mean,el1_mean};
text (az1_mean,el1_mean,str);

但这两个值在不同的两行中。我怎样才能得到这种格式 (az1_mean,el1_mean)?

x = linspace(0,3*pi,200);
y = cos(x) + rand(1,200);  
y_mean = mean(y); x_mean = mean(x)    
h1 = figure(1);
scatter(x,y)
xlabel('Azimuth); ylabel('Elevati');
hold on;
plot(x_mean,y_mean,'wp'); hold on;
str = {x_mean,y_mean};
text (x_mean,y_mean,str);
hold off;

text 函数中,如果将文本参数作为元胞数组提供,则元胞数组中的新 row/column 将被视为文本的新行。看看this example.

要解决您的问题,只需将 x_meany_mean 显式转换为字符数组,然后将它们与外面的括号和中间的逗号连接起来,即

text(x_mean, y_mean, ['(', num2str(x_mean), ', ', num2str(y_mean), ')']);

顺便说一句,不需要多个hold on。除非你 hold off.

,否则单个 hold on 将继续坚持