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

8 次查看(过去 30 天)
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