计数器不更新

Counters do not update

这对我来说是第一次。我已经开始使用 GUIDE,经过温和的咒骂后,我已经跌入谷底。我在 m 文件中设置了一个计数器,但由于某种原因它没有更新。请你帮助我好吗。计数器称为 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);

我已经在函数的开头声明了这个变量

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.

并且该函数是通过按下按钮调用的。这稍后将成为一个连续调用的函数,因此基于按钮按下信息的计数器将不起作用。

function printOnce_Callback(hObject, eventdata, handles)

display(streamSensor_1_2_3(hObject, handles));

guidata(hObject, handles);

在您按钮的回调函数中,不要再次调用 guidata(hObject, handles);,除非您的 streamSensor_1_2_3() 函数 returns 已更新 handles。因此,只需删除函数 printOnce_Callback(hObject, eventdata, handles).

中的最后一行