Struct contents reference from a non-struct array object.
13 views (last 30 days)
Show older comments
I'm trying to do simple pop-up menu. But all I get is this error - Struct contents reference from a non-struct array object. I don't know why because i have simple code to get a value from options, any ideas how to solve this? Here's code:
function noise_pop_CreateFcn(hObject, eventdata, handles)
% hObject handle to noise_pop (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
a = get(handles.noise_pop, 'value')
if (a == 1)
fprintf('hello');
else
fprintf('hi');
end
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
0 Comments
Answers (2)
Guillaume
on 16 Mar 2018
If the line generating the error is
a = get(handles.noise_pop, 'value')
then the cause of the error is that the handles your receive in your callback handler is not the handles structure of your GUI but something else (that is not a structure).
How is your callback defined? Most likely you made a mistake there.
0 Comments
Image Analyst
on 16 Mar 2018
You might not be able to get properties from the noise_pop popup until it's been created. If the control is not yet done being created, how can you query any properties of it? So that means, don't put your code in the Create function. I NEVER put any code in the create functions - I totally ignore them. Put any code in the noise_pop_Callback() function instead. Or you can put that code in any other non-create callback function.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!