Filter löschen
Filter löschen

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

8 Ansichten (letzte 30 Tage)
Jeremy James
Jeremy James am 14 Jan. 2021
Beantwortet: Suraj am 18 Jul. 2024 um 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

Antworten (1)

Suraj
Suraj am 18 Jul. 2024 um 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 !

Kategorien

Mehr zu MATLAB Mobile finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by