Matlab GUIDE: how can I scatter when the user clicks?
I want to program the 'axes1' section of a new GUIDE project in a way that it scatters the points inside the axes when the user clicks on them.
I am new to GUIDE and I don't fully understand how hObjec, handles, etc. work. What I have gathered so far from other posts is the following piece of code:
% --- Executes on mouse press over axes background. function axes1_ButtonDownFcn(hObject, eventdata, handles) % hObject handle to axes1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) %axesHandle = get(hObject,'Parent'); coordinates = get(hObject,'CurrentPoint'); coordinates = coordinates(1,1:2); scatter(coordinates(1),coordinates(2));
I am not using the 'get(hObject,'Parent')' section because that was used in the case you use an image to display in the axes and that is not my case.
Can someone please explain how can I do this?
Thanks in advance for your time
I solved this months ago but I didn't post the solution!
It was easier than I thought, I just had to store each mouse press as a (x, y) point and then use plot:
% ND = Nodes in the network ND = zeros(N,2); ND(1,:) = ginput(1); plot(ND(1,1),ND(1,2),'ko','MarkerSize',12); hold on; for i=2:N ND(i,:) = ginput(1); plot(ND(i,1),ND(i,2),'ko','MarkerSize',12); end