Plot an image on one of four axes in GUI

Hi there,
Self-taught 2013a MATLAB beginner here, working on a pet project. I've a GUI with 1 botton and 2 axes. The button and axes layout was done in GUIDE if that helps.
Within the button callback, a user picks a group of images to be processed, these are read into a cell array.
They also choose 1 baseline image that will be subtracted from all others.
I'd like to plot the first image from this cell array - both before and after being processed, and the baseline image.
I've run into the error "Attempt to reference field of non-structure array." and can't seem to resolve it.
The code where the baseline image is read in, and I attempt to plot it on axes 1:
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Open specific directory area where all my images live, prompt for file:
[baseFileName, folder] = uigetfile('C:\Users\me\*.*','Specify MASTERDARK file to use');
% Create the full file name.
fullImageFileName = fullfile(folder, baseFileName);
% read it in
MASTERDARK = imread(fullImageFileName);
% Plot it on axes 1:
axes(handles.axes1); % Switches focus to this axes object.
imshow(MASTERDARK); % Display image
.... goes on from here, but this is the first point at which the error message is thrown.
Note: If I skip this bit, I get the same error plotting the first image out of the cell array 'imdata':
axes(handles.axes2);
imshow(imdata{1,1});
++++++++++++++++++++++++++++++++++++++++++++++++++++++ Full text of the error:
Attempt to reference field of non-structure array.
Error in KensGUInumberThree>pushbutton1_Callback (line 90)
axes(handles.axes1); % Switches focus to this axes object.
Error in gui_mainfcn (line 96)
feval(varargin{:});
Error in KensGUInumberThree (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
@(hObject,eventdata)KensGUInumberThree('pushbutton1_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
++++++++++++++++++++++++++++++++++++++++++++++++++++++
Do I need to create a line like this for each axes?
function axes1_Callback(hObject, eventdata, handles)
Any help greatly appreciated.

1 Comment

The error is occurring because handles doesn't contain axes1 or axes2.
Check the contents of handles, and how to fix it ought to be apparent.

Sign in to comment.

 Accepted Answer

You either don't have an axes control with a tag property of axes1 like you thought, or you used clear, clearvars, or some other flavor of clear. Look at the tag property in Property inspector when you double click on the axes control in GUIDE. Then search for "clear" in your m-file source code.

More Answers (1)

Ken
Ken on 20 May 2013
Ahhhh.. I think I may have found my error.
I must have 'cleared' handles out during testing wihtout knowing what I was doing, and saved that uninteded change.
A new GUI created from scratch worked as intended, throwing one image on the 1st axes, and another on the 2nd.
Thanks for the format fix Image Analyst!
Ken

1 Comment

Clear is often the culprit. It's fine in a little test script but if you copy it into a GUIDE callback it wreaks havoc. Glad I could help. And next time, put comments as a comment, not as a new, additional "answer" to your original question.

Sign in to comment.

Categories

Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!