![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1736577/image.png)
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)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/488083/image.png)
I've managed to stream the data to MATLAB but I'm unsure how to visualise this. Could someone kindly help?
Thank you,
Jeremy
0 件のコメント
回答 (1 件)
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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1736577/image.png)
I hope this helps !
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!