Struct contents reference from a non-struct array object.

14 次查看(过去 30 天)
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

回答(2 个)

Guillaume
Guillaume 2018-3-16
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.

Image Analyst
Image Analyst 2018-3-16
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.

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by