0

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);
SeinopSys
  • 8,787
  • 10
  • 62
  • 110
  • Have you checked the value by putting a break point at the line where you increment the counter? – Navan Mar 09 '15 at 16:49

1 Answers1

0

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).

scmg
  • 1,904
  • 1
  • 15
  • 24
  • Thanks a bunch it works! I have a problem with the comet plot not updating. I assume that the plot is newly drawn each time the function is called. Any idea how I could implement the comet plot to plot the data as it is being read. Thanks in advanced. – user4650459 Mar 10 '15 at 08:29
  • i don't really get what you mean, you can place a new question with some sample code describing your problems and ppl will help :-) – scmg Mar 10 '15 at 16:21
  • Thanks for the help scmg. I got it working by using plot and extracting the data and then appending the newly read data to make a realtime graph. You guys are friggin' awesome. Now onwards to making the best GUI ever. – user4650459 Mar 11 '15 at 09:21