17 lines
589 B
Matlab
17 lines
589 B
Matlab
function q = quartiles(x)
|
|
% returns a vector with the first, second, and third quartile
|
|
% of the vector x
|
|
xs = sort(x);
|
|
if (length(xs) == 0) % no data
|
|
q = [];
|
|
elseif (rem(length(xs), 2) == 0) % even number of data
|
|
index = length(xs)/2;
|
|
m = (xs(index) + xs(index+1))/2;
|
|
q = [round(xs(length(xs)/4)), m, xs(round(3*length(xs)/4))];
|
|
else % odd number of data
|
|
index = (length(xs) + 1)/2;
|
|
m = xs(index);
|
|
q = [round(xs(length(xs)/4)), m, xs(round(3*length(xs)/4))];
|
|
end
|
|
end
|