Intermittent errors when calling timers with cell arrays for timerfcn argument
1 view (last 30 days)
Show older comments
I'm having a lot of trouble tracking down a bug in my GUI. Currently, I have a large chunks of data coming in via UDP, and being written to a file by a separate program. My matlab program then reads the data, and stores it in a circular buffer.
I've created a GUI to present the data using two axes, axes_channel_data and axes_topographic. I only want to show one axes and it's plots at a time, so I have two radiobuttons to select which axes to display. Each axes's plot is created in a function, update_channel_data and update_topographic. I'm currently using one timer, tUpdate_graph, to call both functions. When the radio button is pressed for axes_channel_data, I stop the timer, change the timerfcn to {@update_channel_data,handles}, and restart the timer. The same is true for the topographic plot, {@update_topographic,handles}. My problem is that occasionally when switching between the two axes, an error occurs; "cell contents reference a non-cell array" in timer tUpdate_graph.
This error only occurs when the program is actively receiving data. I have another timer, tUpdate_data, that reads the data file every .01 seconds. When tUpdata_data is running, I occasionally have the error occur in tUpdate_graph.
I've tried using the command dbstop if error, and the program doesn't stop. I've also placed a disp('function_name') at the top of the update functions. When the error occurs, disp doesn't execute, meaning the function isn't successfully being called by the timer. I've also used get(handles.tUpdate_graph,'TimerFcn') to output the timer function after changing the timer, but before restarting it, and the timer function is identical for both successful cases and error cases. What's the next step in troubleshooting this problem?
radio button callback (topographic and channel data are identical, except passing a different field name to change_state):
% --- Executes on button press in radio_channeldata.
function radio_channeldata_Callback(hObject, eventdata, handles)
% hObject handle to radio_channeldata (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles = guidata(handles.figure_main);
% Hint: get(hObject,'Value') returns toggle state of radio_channeldata
if get(hObject,'Value')
colorbar('peer',handles.axes_topographic,'off');
% get current timer state (start/stop)
timer_state = get(handles.tUpdate_graph,'Running');
% stop timer if running
if strcmp(timer_state,'on')
stop(handles.tUpdate_graph);
end
% Update GUI properties
change_state(handles,'channel_data');
disp('channel Data')
temp = get(handles.tUpdate_graph,'TimerFcn')
disp(temp{2})
% restart timer (if it was previously on)
if strcmp(timer_state,'on')
start(handles.tUpdate_graph)
end
end
guidata(hObject, handles);
Change_state:
function change_state(handles, statename)
% This function is used to transition between GUI states, using the preset
% values in the statelist.
%
% handles structure with GUI handles and statelist.
% statename state to transition to (handles.state.<statename>) (string)
handles = guidata(handles.figure_main);
drawnow;
if isfield(handles.state,statename)
for index = 1:size(handles.state.(statename),1)
set(handles.state.(statename){index,1},...
handles.state.(statename){index,2},...
handles.state.(statename){index,3}...
);
end
else
error('structure field ''%c'' doesn''t exist',statename);
end
The relevant excerpt from the state struct:
% This file exists to create a structure, 'state', containing all the
% settings that must be changed when moving between modes (i.e, when
% changing from a topographic map to channel data. The structure is
% composed as follows:
% state.<mode_name> = [{<object handle>} {<property>} {<value>};
% {<object handle>} {<property>} {<value>}];
% It is assumed change_state.m is used to set all properties.
state.topographic = [...
{handles.tUpdate_graph},{'TimerFcn'},{{@update_topographic,handles}};...
{handles.channel_data},{'Visible'},{'off'};...
{handles.topographic},{'Visible'},{'on'};...
.
.
.
];
state.channel_data = [...
{handles.tUpdate_graph},{'TimerFcn'},{{@update_channeldata,handles}};...
{handles.topographic},{'Visible'},{'off'};...
{handles.channel_data},{'Visible'},{'on'};...
.
.
.
];
Give me a shout if more code is necessary.
0 Comments
Answers (0)
See Also
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!