I am trying to move through a series of images in a GUI but receive the following error when pressing the 'next block' button following the load button. The 'next block' button should display on the two axes on the screen the next 2 figures
{Error: Struct contents reference from a non-struct array object.
Error in Block_Sort>next_block_Callback (line 93) a1 = axes(handles.axes1);
Error in gui_mainfcn (line 95) feval(varargin{:});
Error in Block_Sort (line 42) gui_mainfcn(gui_State, varargin{:});
Error in matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)Block_Sort('next_block_Callback',hObject,eventdata,guidata(hObject)) 93 a1 = axes(handles.axes1);
} function next_block_Callback(hObject, eventdata, handles)
% hObject handle to next_block (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
images = guidata(hObject);
a1 = axes(handles.axes1);
a2 = axes(handles.axes2);
for i = 1:length(images)
I = images{i+1};
J = images{i+2};
imshow(a1,I);
imshow(a2,J);
end
function load_Callback(hObject, eventdata, handles)
% hObject handle to load (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
addpath(pwd)
animal = evalin('base','animal');
foldname = ['Selected-Figures-' animal '*'];
filename = dir(foldname);
dinfo = dir(filename.name);
addpath(filename.name);
names_cell = {dinfo.name};
names_cell = names_cell(3:end);
images = cell(1,length(names_cell));
for i = 1:length(names_cell)
curr_file_name = names_cell{i};
curr_im = imread(curr_file_name);
images{i} = curr_im;
end
guidata(hObject,images);
I = imread(names_cell{1});
I = imresize(I,2);
J = imread(names_cell{2});
J = imresize(J,2);
axes(handles.axes1);
imshow(I);
axes(handles.axes2);
imshow(J);

2 comentarios

Geoff Hayes
Geoff Hayes el 6 de Jul. de 2018
Sophie - how are you launching your GUI? From the command line, the run button in the m-file editor, or through GUIDE?
Or, are you double-clicking on the figure file? I wonder if this is the case since the error message is telling you Struct contents reference from a non-struct array object which seems to correspond to your code handles.axes1. If you open your GUI through the figure file, then this will not properly initialize your GUI and so it will be unusable. You need to launch the GUI through one of the above three methods.
Arwinsyah Putra
Arwinsyah Putra el 11 de Ag. de 2020
thanks ;)
it's really help

Iniciar sesión para comentar.

 Respuesta aceptada

OCDER
OCDER el 6 de Jul. de 2018
Editada: OCDER el 6 de Jul. de 2018

1 voto

Geoff's answer will probably resolve your initial error, but you'll probably run into issues at the same place. Note that Axes cannot return an output if used like a1 = axes(handles.axes1).
EXAMPLE:
handles.axes1 = axes; %Creates a new axes
a1 = axes(handles.axes1); %ERROR: Too many output arguments
If you want to draw an image in a particular axes, use the 'Parent' option like this:
imshow(I, 'parent', handles.axes1)
That way, you don't have to track which axes is the first axes, etc. Another way is to directly set the imshow's CData property.
Ix = imshow([], 'parent', handles.axes1); %initialize the imshow handle somewhere
Ix.CData = rand(100); %change the image shown by the imshow area

11 comentarios

Sophie Lis
Sophie Lis el 6 de Jul. de 2018
I did it like this, but I still get the same error. I also initialize the correct way
function next_block_Callback(hObject, eventdata, handles)
images = guidata(hObject);
for i = 1:length(images)
imshow(images{i+1},'parent',handles.axes1);
imshow(images{i+2},'parent',handles.axes2);
end
Geoff Hayes
Geoff Hayes el 6 de Jul. de 2018
Sophie - how are you launching the GUI? Are you double-clicking on the figure file?
Sophie Lis
Sophie Lis el 6 de Jul. de 2018
No, I am running it from the .m file
Geoff Hayes
Geoff Hayes el 6 de Jul. de 2018
And the error corresponds to
mshow(images{i+1},'parent',handles.axes1);
?
Please copy and paste the full error message to this question. Also, try putting a break point at this line of code and then re-run your GUI. When the debugger pauses at this line, look at the handles variable. What can you tell us about it? (Is it a struct? Does it have a axes1 member? etc.)
Sophie Lis
Sophie Lis el 6 de Jul. de 2018
Struct contents reference from a non-struct array object.
Error in Block_Sort>next_block_Callback (line 96)
imshow(images{i+1},'parent',handles.axes1);
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in Block_Sort (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)Block_Sort('next_block_Callback',hObject,eventdata,guidata(hObject))
96 imshow(images{i+1},'parent',handles.axes1);
Sophie Lis
Sophie Lis el 6 de Jul. de 2018
Editada: Sophie Lis el 6 de Jul. de 2018
Handles is also very strange, it does not contain axes1 (i attached a screenshot) It looks like the handles are just the figures in the cell array images
OCDER
OCDER el 6 de Jul. de 2018
Does the OpeningFcn have the guidata(hObject, handles) line it? EX:
function myGUI_OpeningFcn(hObject, eventdata, handles, varargin)
guidata(hObject, handles);
Can you upload the full .m and .fig file so we can see what's going on?
Sophie Lis
Sophie Lis el 6 de Jul. de 2018
Yes, it has this line. Here they are. Thank you so much!
OCDER
OCDER el 6 de Jul. de 2018
I see. The issues is when you use guidata(hObject, images), you override the GUI data that was supposed to store the handles instead.
Here's how to begin fixing it.
function load_Callback(hObject, eventdata, handles)
% hObject handle to load (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
addpath(pwd)
animal = evalin('base','animal');
foldname = ['Selected-Figures-' animal '*'];
filename = dir(foldname);
dinfo = dir(filename.name);
addpath(filename.name);
names_cell = {dinfo.name};
names_cell = names_cell(3:end);
%%%%%images = cell(1,length(names_cell));
handles.images = cell(1,length(names_cell));
for i = 1:length(names_cell)
curr_file_name = names_cell{i};
curr_im = imread(curr_file_name);
%%%%%images{i} = curr_im;
handles.images{i} = curr_im;
end
%%%%%guidata(hObject,images); DELETE!!!! ERROR, override handles variable
guidata(hObject,handles)
I = imread(names_cell{1});
J = imread(names_cell{2});
imshow(I, 'parent', handles.axes1)
imshow(J, 'parent', handles.axes2)
So instead of trying to store images to guidata, store it as a field of handles like
handles.images = ....;
guidata(hObject, handles);
To get the images, use handles.images.
Sophie Lis
Sophie Lis el 6 de Jul. de 2018
It works, thank you so much!!
OCDER
OCDER el 6 de Jul. de 2018
You're welcome!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Creating, Deleting, and Querying Graphics Objects en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 6 de Jul. de 2018

Comentada:

el 11 de Ag. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by