

% The output of this function is a matrix of size 2xlength(index)
% Each row correspond to each index
% The first column is the row number of the index
% The second column is the column number of the index


function coord=position(index, row, column)

% create a test input
%A=zeros(500,1000);
%A(15)=200; A(34)=200; A(9)=200; A(49:300)=200; A(500:1000)=200;
%index=find( A>100 );
%row=500;
%column=1000; 

for( i=1:length(index) )
   tmp = index(i);
   r = mod(tmp,row);
   if( r == 0 )
      coord(i,1) = row;
   else
      coord(i,1) = r;
   end  % if
   c=1;
   while( tmp > row )
      tmp=tmp-row;
      c=c+1; 
   end  % while
   coord(i,2) = c;
end  % for
