1 function [Mode, Number_values] = M_shift2 (Values, Window_radius, Initial, Mv)
\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);
\r
6 Next_val = round(Initial);
\r
7 L1 = size(Values, 1); L2 = size(Values, 2);
\r
9 % global plot_number plot_xmin plot_xmax plot_ymin plot_ymax
\r
10 % if plot_number == 1
\r
13 % [II, JJ] = find(Values > 0);
\r
14 % if plot_number == 1
\r
15 % plot_xmin = min(II)-Window_radius/2;
\r
16 % plot_xmax = max(II)+Window_radius/2;
\r
17 % plot_ymin = min(JJ)-Window_radius/2;
\r
18 % plot_ymax = max(JJ)+Window_radius/2;
\r
21 % subplot(2, 2, plot_number);
\r
22 % plot(II, JJ, '.');
\r
23 % xlabel('first principal component');
\r
24 % ylabel('second prrincipal component');
\r
25 % axis([plot_xmin plot_xmax plot_ymin plot_ymax])
\r
26 % text(Next_val(1)+Window_radius/1.8, Next_val(2)-Window_radius/4, 'Initial');
\r
28 while norm(Next_val-Current_val) > 2
\r
30 % Draw_rect(Window_radius, Window_radius, Next_val, 'magenta');
\r
32 Current_val = Next_val;
\r
35 max(1, Current_val(1)-Window_radius): ...
\r
36 min(L1, Current_val(1)+Window_radius), ...
\r
37 max(1, Current_val(2)-Window_radius): ...
\r
38 min(L2, Current_val(2)+Window_radius));
\r
39 [x(1, :, :), x(2, :, :)] = ...
\r
41 [max(1, Current_val(1)-Window_radius): ...
\r
42 min(L1, Current_val(1)+Window_radius)], ...
\r
43 [max(1, Current_val(2)-Window_radius): ...
\r
44 min(L2, Current_val(2)+Window_radius)]);
\r
47 Sum_values(1, i) = sum(sum(squeeze(x(i, :, :)) .* Window));
\r
49 Number_values = sum(sum(Window));
\r
51 if Number_values < Mv
\r
57 Next_val = round(Sum_values/Number_values);
\r
61 % text(Next_val(1)+Window_radius/1.8, Next_val(2)+Window_radius/4, 'Final');
\r
62 % plot_number = plot_number+1;
\r