Skip to content

Commit 345694a

Browse files
committed
Use chi2inv (from stats+ML toolbox) or chi2inv_rtb from RTB
update comments
1 parent b9c90fa commit 345694a

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

plot_ellipse.m

+12-5
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,11 @@
3737
% - The ellipse is added to the current plot irrespective of hold status.
3838
% - Shadow option only valid for ellipsoids.
3939
% - If a confidence interval is given then E is interpretted as a covariance
40-
% matrix and the ellipse size is computed using an approximate inverse
41-
% chi-squared function.
40+
% matrix and the ellipse size is computed using an inverse chi-squared function.
41+
% This requires CHI2INV in the Statistics and Machine Learning Toolbox or
42+
% CHI2INV_RTB from the Robotics Toolbox for MATLAB.
4243
%
43-
% See also PLOT_ELLIPSE_INV, PLOT_CIRCLE, PLOT_BOX, PLOT_POLY, CH2INV_RTB.
44+
% See also PLOT_ELLIPSE_INV, PLOT_CIRCLE, PLOT_BOX, PLOT_POLY, CH2INV.
4445

4546
% Copyright (C) 1993-2019 Peter I. Corke
4647
%
@@ -89,8 +90,14 @@
8990
% process the probability
9091
if isempty(opt.confidence)
9192
s = 1;
92-
else
93-
s = sqrt(chi2inv_rtb(opt.confidence, 2));
93+
else
94+
if exist('chi2inv') == 2
95+
s = sqrt(chi2inv(opt.confidence, 2));
96+
elseif exist('chi2inv_rtb') == 2
97+
s = sqrt(chi2inv_rtb(opt.confidence, 2));
98+
else
99+
error('SMTB:missingfunc', 'Requires Stats Toolbox or RTB to be installed');
100+
end
94101
end
95102

96103
if length(arglist) > 0 && isnumeric(arglist{1})

unit_test/plotXTest.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ function ellipse2d_test(tc)
261261
plot_ellipse(E, [0 8 0.5], 'edgecolor', 'r', 'fillcolor', 'c', 'alpha', 0.5, 'LineWidth', 3);
262262
plot_ellipse(E, [4 8], 'b--', 'LineWidth', 3);
263263
plot_ellipse(E, 'confidence', 0.5);
264-
264+
265265
h = plot_ellipse(E);
266266
plot_ellipse(E, [1 1], 'alter', h);
267267
tc.verifyError(@() plot_ellipse(E, 'alter', 7), 'SMTB:plot_ellipse:badarg');

0 commit comments

Comments
 (0)