When I run my code on the serial monitor, I can a clear line of data similar to the line below:
X: -6 Y: 16 Z: 4092 t(ms): 74
however when I go to retrieve a line of data in Matlab, I get something similar to this:
Line =
î~ '� $ X: -2 Y: 14 Z: 4084 t(ms): 91781
Î~ &� ' X: 0 Y: 28 Z: 4096 t(ms): 91803
÷~ '� $ X: -4 Y: 14 Z: 4076 t(ms): 91826
Ë~ '� ' X: -8 Y: 16 Z: 4062 t(ms): 91848
Ã~ (� $ X: -12 Y: 16 Z: 4086 t(ms): 91871
™~ '� ' X: -16 Y: 2 Z: 4078 t(ms): 91893
Â~ &� $ X: -8 Y: 8 Z: 4052 t(ms): 91916
where I get multiple lines of data and these characters at the beginning of each line. Can you please give me some advice on how to get rid of those characters at the beginning of each line and how to grab only one line of data at a time?
And here is the Matlab code that I am using:
%%
close all
clear all
clc
%% Setup
% Clears open COM ports that are already in use by MATLAB
instrreset
% Sets communication channel with the sensor to COM4
s = serial('COM4');
% Sets the baud rate for the connection
% This must be the same baud rate of the XBee transmission
set(s, 'BaudRate', 57600);
% Open the data file for recording the sensor data
% Was previously a .dat file. Can be changed easily.
dat = fopen('sens_data_buoy.txt', 'wt');
fprintf(dat,'x data \t y data \t \t z data \t time(ms) \t time(s) \t time(s) \n');
% Opens the communication channel with the sensor
fopen(s);
ii = 1
%%
Number_of_Samples = 50;
fprintf('Setup Complete. \nStarting data collection.\n');
while ii <= Number_of_Samples
Line = fgets(s)
ii = ii + 1;
end
fclose(s);
fclose(dat);
delete(s);
clear s;
Thank you.