arrays - MATLAB Add Mouse Click Coordinate to Matrix? -


i creating image processing project in matlab. want 5 coordinates image mouse , save them matrix. when run project, click once matrix taking same coordinates. how can fix ?

function imageclickcallback ( objecthandle , eventdata ) array = 3:2; = 1:3    axeshandle  = get(objecthandle,'parent');    coordinates = get(axeshandle,'currentpoint');     coordinates = coordinates(1,1:2);    array(i,1) = coordinates(1);    array(i,2) = coordinates(2); end disp(array); 

for example when click point on image, taking result. can't select points.

99.3806   37.1915  99.3806   37.1915 99.3806   37.1915 

a safer alternative use ginput, can select variable number of points , store coordinates easily. don't need loop; coordinates stored once points selected.

here simple example:

clear clc close  = imread('peppers.png');  imshow(a,[]); hold on  %// number of points n = 5;  array = zeros(n,2);  %// use loop , plot 1 point @ time. k = 1:n     [array(k,1),array(k,2)] = ginput(1);     %// display points    scatter(array(k,1),array(k,2),60,'k','filled')  end 

sample output array:

   123.0000   87.0000    95.0000  206.0000   256.0000   85.0000   236.0000  253.0000   395.0000  117.0000 

and image points displayed:

enter image description here

therefore, this:

function imageclickcallback ( objecthandle , eventdata )     array = zeros(3,2);     [array(:,1),array(:,2)] = ginput(3);