adjustPolarAngles

Version 1.0.0 (2,43 ko) par Ran Yang
A function to robustly shift sets of non-uniform angular values for better downstream statistical analyses, such as angular mean.
1 téléchargement
Mise à jour 13 mai 2024

Afficher la licence

USAGE:
a = adjustPolarAngles(angles);
DESCRIPTION:
adjustPolarAngles attempts to (re)organize a set of radian angles originally in the range (-pi, pi] into a "continuous" distribution for robust statistical compatibility and data visualization. This is because -pi is equivalent to pi in polar coordinates but produces inconsistent results depending on the frame of reference.
This function was primarily designed to work on multiple, large datasets with non-uniform distributions and is a more generalized version of existing functions such as meanangle, which only calculates angular mean. The output of adjustPolarAngles is directly compatible with standard functions such as mean, median, and std, enabling more downstream analyses than just angular mean.
INPUTS:
  • angles: A numerical vector within the range (-pi, pi]. All input data should be pre-adjusted to the equivalent angular values within this range and be in RADIANS.
OUTPUTS:
  • a: A numerical vector with the same size as angles, but certain entries may be shifted by 2*pi. Entry indices are not changed between angles and a, i.e. angles(ind) and a(ind) are polar equivalents, but not necessary numerically equivalent, such as -pi/4 may be expressed as 7*pi/4.
EXAMPLE:
% make up some "discontinuous" data points due to wrap around at -pi / pi and fix them
n = 200;
data = normrnd(pi + pi/16, pi/4, [n, 1]);
data(data > pi) = data(data > pi) - 2*pi;
a = adjustPolarAngles(data);
% visually validate results
figure, hold on
cmap = parula(8); % use some pretty colors
[x, y] = pol2cart(data, unifrnd(0.9, 1.1, [n, 1])); % plot original angles, jitter radii
scatter(x, y, 8, 'marker', 'o', 'markeredgecolor', 'none', 'markerfacecolor', cmap(3, :));
[x, y] = pol2cart(mean(data), 1); % plot original angular mean
scatter(x, y, 12, 'marker', 'o', 'markeredgecolor', 'none', 'markerfacecolor', cmap(5, :));
text(x, y, ' \leftarrow original angular mean', 'horizontalalignment', 'left')
[x, y] = pol2cart(mean(a), 1); % show more accurate angular mean
scatter(x, y, 12, 'marker', 'o', 'markeredgecolor', 'none', 'markerfacecolor', cmap(6, :));
text(x, y, 'accurate angular mean \rightarrow ', 'horizontalalignment', 'right')
xlim([-2, 2]), ylim([-2, 2]), axis equal

Citation pour cette source

Ran Yang (2024). adjustPolarAngles (https://www.mathworks.com/matlabcentral/fileexchange/165841-adjustpolarangles), MATLAB Central File Exchange. Récupéré le .

Compatibilité avec les versions de MATLAB
Créé avec R2023b
Compatible avec toutes les versions
Plateformes compatibles
Windows macOS Linux
Remerciements

Inspiré par : meanangle, Mean Angle

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Publié le Notes de version
1.0.0