GUI ERROR : Struct contents reference from a non-struct array object.
8 次查看(过去 30 天)
显示 更早的评论
function start_Callback(hObject, eventdata, handles)
global isStart startTime
isStart= 1;
set(handles.slider_chopper, 'Value', startTime);
guidata(hObject, handles)
function stop_Callback(hObject, eventdata, handles)
global isStart stopTime
isStart=0;
set(handles.slider_chopper, 'Value', stopTime);
guidata(hObject, handles)
function slider_chopper_Callback(hObject, eventdata, handles)
global startTime stopTime isStart
if isStart== 1
startTime= get(hObject,'Value');
else
stopTime= get(hObject,'Value');
end
function slider_chopper_CreateFcn(hObject, eventdata, handles)
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
global startTime stopTime isStart;
startTime = 0;
stopTime = 1;
isStart = 1;
So I was working with GUI, and ran across this problem. What the program is supposed to do, is if I click the start button (tagged start), and move the position of the slider (tagged slider_chopper), it will store the position in a variable startTime and does the same after clicking on the stop (tagged stop). This part works.
The part that does not work, is when I click start button again, the program is supposed to set the position of slider to the value of startTime, and same for the stop button and stopTime. So I used set in callback functions for start and stop to accomplish this, but it's giving me error (right after I click start or stop button) that says:
Struct contents reference from a non-struct array object.
Error in GUI>start_Callback (line 89)
set(handles.slider_chopper, 'Value', startTime);
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in GUI (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)GUI('start_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback
What is the problem, and how do I fix this?
0 个评论
回答(1 个)
Walter Roberson
2016-3-6
You do not appear to be changing the handles structure in your start and stop callbacks, so I recommend you remove the
guidata(hObject, handles)
You should debug. At the command line, command
dbstop if error
and then run the program. When it stops with the error, have a look at class(handles.slider_chopper) and at size(handles.slider_chopper) and see what is there.
Are there any other functions that you invoked between clicking on stop and clicking on start again? functions that might possibly be calling guidata() with bad handles structure?
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Entering Commands 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!