So I am trying to continuously read data from an arduino-based instrument and plot it using MATLAB, but I'm getting hung up on something that seems really basic. I declare a matrix A in my OpeningFcn (not showing comments and code relevant to serial initialization, which all works just fine):
function tutorial_OpeningFcn(hObject, eventdata, handles, varargin)
handles.A = [0 1];
handles.arduino_port.BytesAvailableFcn = {@dataReceivedCallback, handles};
guidata(hObject, handles);
end
and I have a callback function for when I receive more than 50 bytes of serial data (which I have confirmed is working beautifully)
function dataReceivedCallback(hObject, eventdata, handles)
temp = fread(hObject, 50)';
handles.A = [handles.A temp];
end
but for whatever reason it throws an error when I try to assign handles.A, which I have posted below.
Not enough input arguments.
Error in tutorial>dataReceivedCallback (line 98)
handles.A = [handles.A temp];
Error in instrcb (line 42)
feval(val{1}, obj, eventStruct, val{2:end});
Warning: The BytesAvailableFcn is being disabled. To enable the callback property
either connect to the hardware with FOPEN or set the BytesAvailableFcn property.
This seems like a trivial issue, but I can't make heads or tails of it. The same thing happens when I try to increment a simple dummy variable. I'm new to MATLAB and come from a C/C++ background and I'm treating 'handles' like a global class and 'A' like a value variable in that class. I don't see why this doesn't work. The same exact code works when I run it with vanilla variables in the command window.