0

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?

user2738748
  • 1,106
  • 2
  • 19
  • 36
  • I cannot reproduce the error with the provided code. As a side note, there's no reason to write the handles structure back to the invoking object if you haven't changed it. – sco1 Jul 18 '14 at 11:23
  • Thank you. I checked my code again. These are not the lines which cause this error. I found the bug- I incorrectly used the guidata function. – user2738748 Jul 18 '14 at 12:43
  • Happy to help. I should have added this to my comment as well: the documentation for [`guidata`](http://www.mathworks.com/help/matlab/ref/guidata.html) does provide a caveat for using `guidata` in a GUIDE GUI. While you can use the `handles` structure and `guidata` for your own purposes by adding new fields, you must take care not to overwrite the existing handles to your GUI objects for this very reason. – sco1 Jul 18 '14 at 13:27

1 Answers1

0

I had a similar problem. I used a timer object and passed the different axes in a handle object which worked. My application was getting data from multiple cameras in realtime.