How can I save the x and y values obtained from ginput through a for loop?

13 views (last 30 days)
I am working on a problem that requires for me to save an N by M text file containing the content of each box in a grid that is over an image. I created a GUI where the user clicks over the image and a marker (square) is plotted. I am trying to save all the x & y values to determine where on the grid there is a filled box, but since I am using a for loop, the values are replaced each time. I tried creating an empty matrix and storing the values in the matrix but only one set of values is stored. Does anyone have suggestions on how to go about this? This is part of my code:
switch pp case 1
case 2
hold on
[x,y]=ginput(1);
X=[];
for i=1:x_len
if x>x_vals(i) && x<x_vals(i+1)
x=2*x_mid(i)+10;
X=[i];
end
end
Y=[];
for j=1:y_len
if y>y_vals(j) && y<y_vals(j+1)
y=2*y_mid(j)+10;
Y=[j];
end
end
plot(x,y,'s','LineWidth',1,...
'MarkerEdgeColor','r',...
'MarkerFaceColor','r',...
'MarkerSize',6)
hold off

Answers (1)

Azzi Abdelmalek
Azzi Abdelmalek on 10 Jun 2013
data(k,:)=ginput(1);
x=data(k,1)
y=data(k,2)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!