-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathread_plot_matrix_pos.m
More file actions
22 lines (22 loc) · 846 Bytes
/
Copy pathread_plot_matrix_pos.m
File metadata and controls
22 lines (22 loc) · 846 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
function data = read_plot_matrix_pos(mySerial)
nsamples = fscanf(mySerial,'%d'); % first get the number of samples being sent
%fprintf(mySerial);
%fprintf(nsamples);
data = zeros(nsamples,2); % two values per sample: ref and actual
for i=1:nsamples
data(i,:) = fscanf(mySerial,'%d %d'); % read in data from PIC32; angles, in degs
times(i) = (i-1)*0.005; % 0.005 s between samples
end
if nsamples > 1
stairs(times,data(:,1:2)); % plot the reference and actual
else
fprintf('Only 1 sample received\n')
disp(data);
end
% compute the average error
score = mean(abs(data(:,1)-data(:,2)));
fprintf('\nAverage error: %5.1f degrees\n',score);
title(sprintf('Average error: %5.1f degs',score));
ylabel('Angle (deg)');
xlabel('Time (s)');
end