Hi bros and sis,
————————————————————-
Say I have three images named '1.jpg', '2.jpg', and '3.jpg' showing below.
————————————————————-
I also created an axes on a Gui. Showing below.(I have removed the outlines of the axes.)
————————————————————-
What I would like to achieve is that everytime when I click on the axes, it will display a different image, which means 1st time when I click axes it will display '1.jpg'; when I click on the axes again, it will display '2.jpg'; if I click on the axes again, it will display '3.jpg'.
————————————————————-
My problem is that the first time when i click on the axes, it displayed '1.jpg' without problem, but when i click on the axes again, it has no respond to my second click ( see figure below) and never displayed '2.jpg', not to say '3.jpg'.
————————————————————-
In the opening function I defined a variable 'handles.Index' and a 'ButtownDownFcn' named 'click'. See below.
% --- Executes just before t1 is made visible.
function t1_OpeningFcn(hObject, eventdata, handles, varargin)% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to t1 (see VARARGIN)
% Choose default command line output for t1
handles.output = hObject; set(handles.axes1,'xtick',[]); set(handles.axes1,'ytick',[]); set(handles.axes1,'xcolor',[0.94 0.94 0.94]); set(handles.axes1,'ycolor',[0.94 0.94 0.94]); handles.Index = 0; set(handles.axes1,'ButtonDownFcn',@click);% Update handles structure
guidata(hObject, handles);
————————————————————-
In the 'ButtonDownFcn' named 'click', I wrote:
function click(hObject,eventdata) handles = guidata(hObject); handles.Index = handles.Index + 1; fn = sprintf('%d.jpg',handles.Index); RGB = imread(fn); im = image(RGB,'Parent',handles.axes1) set(im,'hittest','off'); % Update handles structure guidata(hObject,handles);
————————————————————-
Anything mistakes I made in the 'ButtonDownFcn' part that stops respond to a mouse click?? Can anyone help please?
Many thanks!
Best Answer