I'm working on a GUI (created with guide in Matlab) with two axes and two pushbuttons. When the user presses pushbutton1 I want to display an image on axes1 and when the user presses pushbutton2 I want to display an image on axis2.
This is my code:
function pushbutton1_Callback(hObject, eventdata, handles)
axes(handles.axes1);
imagesc(table(:,:,1));colormap(gray),axis('square');
guidata(hObject,handles);
function pushbutton2_Callback(hObject, eventdata, handles)
axes(handles.axes2);
imagesc(table(:,:,1));colormap(gray),axis('square');
guidata(hObject,handles);
This code works fine only when the user presses the buttons for the first time. When he does it again, the program crashes and I get the following error: "Reference to non-existent field 'axes1'".
When I display all handles, I see that the handle "axes1" is missing indeed.
I don't get this error when I change the NextPlot property of my axes to "new". However, in that case I can't display images at all. I mean I don't get errors, but I one forth of the image (top right corner) is grey and the rest is white. The plotrange in both dimensions is (0,1), instead of (0,2000). It seems to me that this is only one pixel of my image.
What am I doing wrong?