1 function [Mode, Number_values, Flag] = M_shift3 (Values, Window_radius, Initial, Min_number)
\r
2 % assumes that Values contains cumulative information, i.e.
\r
3 % the number of elements of the particular value in each Values cell
\r
5 Current_val = round(Initial+2);Next_val = round(Initial);
\r
7 L2 = size(Values{1}, 1);
\r
8 L3 = size(Values{1}, 2);
\r
10 while norm(Next_val-Current_val) > 1
\r
11 Current_val = Next_val;
\r
12 clear x; Sum_values(1, 1:3) = zeros(1, 3);Number_values = sparse(1, L1);
\r
13 for i=max(1, Current_val(1)-Window_radius):min(L1, Current_val(1)+Window_radius)
\r
14 [x(1, :, :), x(2, :, :)] = ...
\r
16 [max(1, Current_val(2)-Window_radius): ...
\r
17 min(L2, Current_val(2)+Window_radius)], ...
\r
18 [max(1, Current_val(3)-Window_radius): ...
\r
19 min(L3, Current_val(3)+Window_radius)]);
\r
21 Window = Values{i}(...
\r
22 max(1, Current_val(2)-Window_radius): ...
\r
23 min(L2, Current_val(2)+Window_radius), ...
\r
24 max(1, Current_val(3)-Window_radius): ...
\r
25 min(L3, Current_val(3)+Window_radius));
\r
27 Number_values(i) = sum(sum(Window));
\r
28 Sum_values(1, 1) = Sum_values(1, 1) + Number_values(i)*i;
\r
31 Sum_values(1, j+1) = Sum_values(1, j+1)+sum(sum(squeeze(x(j, :, :)) .* Window));
\r
35 Number_values_sum = sum(Number_values);
\r
37 if Number_values_sum < Min_number
\r
43 Next_val = round(Sum_values/Number_values_sum);
\r