-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmatlab_example.m
73 lines (49 loc) · 1.78 KB
/
matlab_example.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
close all
clear all
clc
comPort = '11';
% Create serial communication object
serialCom = RealTermHandleClass('ComPort',comPort);
% Open comPort
serialCom.opencomport;
% Initialize variables
DELAY_PERIOD = 0.2;
NO_SAMPLES_IN_PLOT = 1000;
numSamples = 0;
plotData = [];
h.figure1 = figure('Name','PLOT'); % Create a handle to figure for plotting data from shimmer
set(h.figure1, 'Position', [600, 150, 800, 600]);
% Create UI control
stopHandle = uicontrol('Style', 'PushButton', ...
'String', 'Close', ...
'Callback', @closeWindow,...
'position',[380 5 80 20]);
while 1
pause(DELAY_PERIOD); % Pause for this period of time on each iteration to allow data to arrive in the buffer
data = serialCom.getdata();
if ~isempty(data) % TRUE if new data has arrived
plotData = [plotData; data];
% Number of samples in plot
numPlotSamples = size(plotData,1);
% Total number of samples
numSamples = numSamples + size(data,1);
if numSamples > NO_SAMPLES_IN_PLOT
plotData = plotData(numPlotSamples-NO_SAMPLES_IN_PLOT+1:end,:);
end
sampleNumber = max(numSamples-NO_SAMPLES_IN_PLOT+1,1):numSamples;
% Plot data
plot(sampleNumber,plotData);
xlim([sampleNumber(1) sampleNumber(end)]);
else
disp("NO DATA")
end
% Close comPort and delete figure
if stopHandle.UserData
serialCom.closecomport;
delete(h.figure1);
break;
end
end
function closeWindow(stopHandle,eventdata)
stopHandle.UserData = true;
end