필터 지우기
필터 지우기

How do I visualise sensor data in MATLAB Online from iPhone app

조회 수: 8 (최근 30일)
Jeremy James
Jeremy James 2021년 1월 14일
답변: Suraj 2024년 7월 18일 4:34
Hi,
I'm looking to experiment and visually oberve the behaviour of phone sensors (accelerometer etc)
I've managed to stream the data to MATLAB but I'm unsure how to visualise this. Could someone kindly help?
Thank you,
Jeremy

답변 (1개)

Suraj
Suraj 2024년 7월 18일 4:34
Hi Jeremy,
It looks like you were succesful in collecting sensor data and you'd like to plot it on MATLAB. I've come up with a script that plots accelerometer data collected from my phone live.
% Start acquiring data from "mobiledev" object "m"
m.Logging = 1;
pause(0.1);
% Figure for live plot
figure;
hX = animatedline('MaximumNumPoints', 100, 'Color', 'r');
hY = animatedline('MaximumNumPoints', 100, 'Color', 'g');
hZ = animatedline('MaximumNumPoints', 100, 'Color', 'b');
legend('accX', 'accY', 'accZ');
ax = gca;
ax.YGrid = 'on';
ax.YLim = [-20 20]; % Adjust according to your expected range
% Initialize time vector for x-axis
timeVec = [];
% Loop for live plotting while data is being collected
while m.Logging == 1
% Read acceleration data
[a, t] = accellog(m);
% If new data is available
if ~isempty(a)
% Append new data to the time vector
timeVec = [timeVec; t];
% Update the plot for each axis
addpoints(hX, t, a(:, 1)); % X-axis acceleration
addpoints(hY, t, a(:, 2)); % Y-axis acceleration
addpoints(hZ, t, a(:, 3)); % Z-axis acceleration
% Update the x-axis limits to focus on last 2 seconds' data
ax.XLim = [max(timeVec) - 2, max(timeVec)];
drawnow;
end
% Pause to control the update rate
pause(0.1);
end
% Stop logging
m.Logging = 0;
Here's a screenshot of the figure that I was able to plot:
I hope this helps !

카테고리

Help CenterFile Exchange에서 MATLAB Mobile에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by