title: matlab GUIDE: storing data from loop in vector
body: <p>I am new to matlab and i need some help. I am trying to make some program, where you can by 2 clicks on picture get a lenght of something. Basicly it works well, but got a problem when trying to algorytmize it. I use <code>ginput</code> to get coordinates and then pythagorean theorem to work with them and make important variable <code>z2</code>. And those variables I want to store in vector so basicly: I pressed <code>push_button1</code> click twice on a picture and get some z2,now when i do the procedure again i want to store the new one with the old one in the same vector 
  <code>[z2_old z2_new]</code>. But basicly every time i tried to make something like this the old ones value is rewritten.</p>
  
  <p>This is the code of my push button:</p>
  
  <p>function pushbutton1_Callback(hObject, EventData, handles)</p>
  
  <pre><code>%counter - number of press (working right)
  counter = get(hObject, 'UserData') + 1;
  set(hObject, 'UserData', counter);
  set(handles.text1, 'String', sprintf('%d', counter));
  </code></pre>
  
  <p>% - ginput part (working right)</p>
  
  <pre><code>c2 = ginput(2);
     q3 = text(c2(1,1),c2(1,2),'X', ...
                  'HorizontalAlignment','center', ...
                  'Color', [1 1 0], ...
                  'FontSize',10);
     q4 = text(c2(2,1),c2(2,2),'X', ...
                  'HorizontalAlignment','center', ...
                  'Color', [1 1 0], ...
                  'FontSize',10);
  </code></pre>
  
  <p>%creating the z2 variable(working right)</p>
  
  <pre><code>x2=c2(1,1)-c2(2,1);
  y2=c2(1,2)-c2(2,2);
  z2=sqrt(x2*x2+y2*y2);
  </code></pre>
  
  <p>% - loop for getting a vector (not ok)</p>
  
  <pre><code>for i=1:counter        
      z(i,1)=z2                
  end
  </code></pre>
  
  <p>So, basicly when I run the button first time and z2 got for example 130, second time 60, third time 210m I want to get z=[130 60 210], now I am still getting something like 1st press:z=[130], 2nd press: z=[60 60], 3rd press: z=[210 210 210], the old values are every time lost. I tried to fix it many ways but its still not working. Its only a small part of my work and i almost run out of time.</p>
  
  <p>Can someone please tell me how should that loop look like? I tried <code>z(end+1)=z2</code> , <code>z=[z z2]</code> , but the result is always the same.</p>
  
  <p>Thanks for your help a lot. I really Appreciate it.</p>