get real-time new coming sensor data from mobile phone, old sensor data is not include?
I want to get real-time sensor data using mobile phone,
% Initialize the mobile device object
m = mobiledev;
% Enable the accelerometer sensor
m.AccelerationSensorEnabled = 1;
% Start logging accelerometer data
m.Logging = 1;
% Set the figure for real-time plotting
figure;
duration = 15; % Duration of data collection in seconds
startTime = tic; % Start the timer
% Loop to collect and display data in real-time for 15 seconds
while toc(startTime) < duration
[accelData, timeStamps] = accellog(m); % Retrieve accelerometer data and timestamps
if ~isempty(accelData)
% Plot X, Y, Z axis acceleration in different colors
plot(timeStamps, accelData(:, 1), ‘r’); hold on;
plot(timeStamps, accelData(:, 2), ‘g’);
plot(timeStamps, accelData(:, 3), ‘b’);
xlabel(‘Time (s)’);
ylabel(‘Acceleration (m/s^2)’);
legend(‘X-axis’, ‘Y-axis’, ‘Z-axis’);
drawnow; % Update the plot in real-time
hold off;
end
pause(0.1); % Pause for smooth plotting
end
% Stop logging after the duration
m.Logging = 0;
% Optionally, retrieve all the logged data for further processing
[accelData, timeStamps] = accellog(m);
The function accellog(m) returns all logged accelerometer data from the start of the logging session, including both old and new data, in every call. It does not return only the new sensor data since the last call.
This means that in the code you provided, each time accellog(m) is called inside the loop, it will return the complete set of logged accelerometer data from the moment m.Logging = 1 was set, up to the current time.
How can I get the new coming sensor data? (logging=0 , logging=1 again is not a good way)I want to get real-time sensor data using mobile phone,
% Initialize the mobile device object
m = mobiledev;
% Enable the accelerometer sensor
m.AccelerationSensorEnabled = 1;
% Start logging accelerometer data
m.Logging = 1;
% Set the figure for real-time plotting
figure;
duration = 15; % Duration of data collection in seconds
startTime = tic; % Start the timer
% Loop to collect and display data in real-time for 15 seconds
while toc(startTime) < duration
[accelData, timeStamps] = accellog(m); % Retrieve accelerometer data and timestamps
if ~isempty(accelData)
% Plot X, Y, Z axis acceleration in different colors
plot(timeStamps, accelData(:, 1), ‘r’); hold on;
plot(timeStamps, accelData(:, 2), ‘g’);
plot(timeStamps, accelData(:, 3), ‘b’);
xlabel(‘Time (s)’);
ylabel(‘Acceleration (m/s^2)’);
legend(‘X-axis’, ‘Y-axis’, ‘Z-axis’);
drawnow; % Update the plot in real-time
hold off;
end
pause(0.1); % Pause for smooth plotting
end
% Stop logging after the duration
m.Logging = 0;
% Optionally, retrieve all the logged data for further processing
[accelData, timeStamps] = accellog(m);
The function accellog(m) returns all logged accelerometer data from the start of the logging session, including both old and new data, in every call. It does not return only the new sensor data since the last call.
This means that in the code you provided, each time accellog(m) is called inside the loop, it will return the complete set of logged accelerometer data from the moment m.Logging = 1 was set, up to the current time.
How can I get the new coming sensor data? (logging=0 , logging=1 again is not a good way) I want to get real-time sensor data using mobile phone,
% Initialize the mobile device object
m = mobiledev;
% Enable the accelerometer sensor
m.AccelerationSensorEnabled = 1;
% Start logging accelerometer data
m.Logging = 1;
% Set the figure for real-time plotting
figure;
duration = 15; % Duration of data collection in seconds
startTime = tic; % Start the timer
% Loop to collect and display data in real-time for 15 seconds
while toc(startTime) < duration
[accelData, timeStamps] = accellog(m); % Retrieve accelerometer data and timestamps
if ~isempty(accelData)
% Plot X, Y, Z axis acceleration in different colors
plot(timeStamps, accelData(:, 1), ‘r’); hold on;
plot(timeStamps, accelData(:, 2), ‘g’);
plot(timeStamps, accelData(:, 3), ‘b’);
xlabel(‘Time (s)’);
ylabel(‘Acceleration (m/s^2)’);
legend(‘X-axis’, ‘Y-axis’, ‘Z-axis’);
drawnow; % Update the plot in real-time
hold off;
end
pause(0.1); % Pause for smooth plotting
end
% Stop logging after the duration
m.Logging = 0;
% Optionally, retrieve all the logged data for further processing
[accelData, timeStamps] = accellog(m);
The function accellog(m) returns all logged accelerometer data from the start of the logging session, including both old and new data, in every call. It does not return only the new sensor data since the last call.
This means that in the code you provided, each time accellog(m) is called inside the loop, it will return the complete set of logged accelerometer data from the moment m.Logging = 1 was set, up to the current time.
How can I get the new coming sensor data? (logging=0 , logging=1 again is not a good way) matlab mobile MATLAB Answers — New Questions