Matlab:在极坐标图中标记数据点

Matlab: Labeling Data Points in a Polar Plot

我有一个有趣的问题要问,我已经彻底搜索过了,令我沮丧的是,似乎没有人遇到过这个问题。我想在 Matlab 的极坐标图中标记所有数据点。至此代码非常简单,如下:

close all
clear all

% Load all the datasets
%load('matlab.mat')

% These lines serve the same purpose as the load('matlab.mat')
PSA=[5.45938528888889;3.13809934444444;5.42622406111111;2.48185610000000];
NSA=[5.32150439444444;0.767944222222222;5.32499505000000;0.420623994444444];
PST=[1.69085714290000;2.68685714290000;0.688857142900000;0.688857142900000];
NST=[2.32914285710000;1.30914285710000;1.30914285710000;0.709142857100000];

% Global Constants
PI=3.14159;

% Converts the data points (in degrees originally) into radians
PSA=PSA.*(PI/180);
NSA=NSA.*(PI/180);

% Scaling, assumed that within the polar plot function that the maximum
% value is 1.0, so I scaled the data set to be fractions of 1 as opposed to
% values of 3
PST_1=PST./3;

figure(1)
polar(PSA,PST,'.');
h=text(PST(1,1), 2, ' \leftarrow foo');
% text(PositiveStationAzimuth(2,1), PositiveStationTime(2,1), ... PositiveStationName(2,1));
% text(PositiveStationAzimuth(3,1), PositiveStationTime(3,1), ... PositiveStationName(3,1));
% text(PositiveStationAzimuth(4,1), PositiveStationTime(4,1), ... PositiveStationName(4,1));
hold on;
polar(NSA,NST,'x');
view([90 270]);

你将不得不原谅我在这件事上的一般糟糕的编码,这实际上是一个朋友的代码片段,他向我求助,我试了一两个小时,他放弃了但我想找到答案。

所以我正在寻找的解决方案是一些命令,它允许我在极坐标系中绘制字符串数组,这些字符串数组由我的数据点定义的位置数组指定。就目前而言,我什至不确定 text(x,y, 'string') 在极坐标平面中的功能。我认为它是为欧几里德坐标系而不是极地而建的。我想知道除了对文本进行硬编码以显示在数据的同一区域之外是否有任何快捷方式。

polar 函数本身完成了所有转换坐标的艰苦工作。所以直接从图中提取值:

h = polar(PSA,PST,'.'); % easiest way to get handle to plot
x = get(h,'XData');
y = get(h,'YData');
text(x,y, ' \leftarrow foo');  % puts same text next to every point
text(x(3),y(3),' \leftarrow three'); % puts text next to specific point

如果您有一个文本列表(例如字符串元胞数组)要放在各个点旁边,您可以使用循环和类似以下内容:

text(x(n),y(n), [' \leftarrow ', stationname{n}]);