Search code examples
matlabmatlab-guidehandles

Counters do not update


This is a first for me. I have started using GUIDE and after mild cussing I have hit rock bottom. I have setup a counter in a m-file but for some reason it does not update. Could you please help me. The counter is called num.

function ack = streamSensor_1_2_3(hObject, handles)

if handles.fileID.BytesAvailable == 0
    fprintf(handles.fileID, 'P')
    display('yes');

%get data from active receiver stations
for l = 1:3
    data_cm(l,:) = fscanf(handles.fileID, ' %f ' );
    display(data_cm);
    set(handles.uitable1, 'data', data_cm);
end

%solve perpendicular view
[at, bt, ct] = flatPlane(data_cm(:,2), data_cm(:,3), data_cm(:,4))
[xr, yr] = reposit(at, bt, ct);
D_angle = dangle(data_cm(:,2), data_cm(:,3), data_cm(:,4), 'deg');

display(handles.num);

comet(handles.axes3, handles.num, D_angle);
handles.num = handles.num +1 ;

%plot knee angle 
    plot3(handles.axes1, data_cm(:,2), data_cm(:,3), data_cm(:,4));
    plot(handles.axes2, xr, yr);
    ylim(handles.axes2,[-1.2 1.2]);
    xlim(handles.axes2,[-1.2 1.2]);
    ack = 1;
else
    ack = 0;
end
guidata(hObject, handles);

I have declared this variable in the opening function

function Knee_DepressAngle_GUI_OpeningFcn(hObject, eventdata, handles, varargin)

% Choose default command line output for Knee_DepressAngle_GUI
handles.output = hObject;
handles.num = 0;
% Update handles structure
guidata(hObject, handles);
...........etc.

And the function is called from a button press. This is later going to be a continuously called function so a counter based on the button press information will not work.

function printOnce_Callback(hObject, eventdata, handles)

display(streamSensor_1_2_3(hObject, handles));

guidata(hObject, handles);

Solution

  • In your button's callback function, don't call guidata(hObject, handles); again, unless your streamSensor_1_2_3() function returns the updated handles. So, simply delete the last line in function printOnce_Callback(hObject, eventdata, handles).