How can I fix my rolling plot of Matlab Mobile's accelerometer?

57 ビュー (過去 30 日間)
Anthony Beckner
Anthony Beckner 2015 年 8 月 14 日
コメント済み: Shivanshu Singh 2023 年 8 月 28 日
So, I am using Matlab Mobile to try and make a rolling plot that updates with the z axis of the accelerometer data from my android phone. I connected correctly and have written this code which works:
%connect to phone and get accel data
clear m
m = mobiledev;
m.AccelerationSensorEnabled = 1;
m.Logging = 1;
%initialize data for rolling plot
data = zeros(1,200);
tic
while (toc < 30)%run for 30 secs
%read from accel
a = m.Acceleration;
%conditional prevents it from indexing an empty array the first couple
%of times
if(exist('a','var')&&~isempty(a))
%get new z coordinate
newPoint = a(3);
%concatenate and pop oldest point off
data = [data(2:length(data)) newPoint];
%draw plot with set axes
plot(data);
axis([0 200 -15 15]);
drawnow
end
end
My problem is that the resulting rolling plot doesn't resample the data quick enough for what I want. It results in a stepfunction that updates every second or so. Is there anyway to make it resample faster or is this simply due to the nature of the matlab mobile wifi connection? If so, is it possible to connect with bluetooth or some other method such that matlab gets updated points more frequently?
  1 件のコメント
Adarsh Singh
Adarsh Singh 2022 年 10 月 4 日
I'm unable to connect my PC with my mobile to get realtime data of mobile sensor on my PC ,plz help me.....

サインインしてコメントする。

採用された回答

James Wiken
James Wiken 2015 年 8 月 17 日
You can improve the sample rate for your rolling plot by using the 'accellog' function, similar to the example seen here:
The following code is a modification of your provided code using this function. The resulting plot has a update rate of about 1 Hz with a data sample rate of about 10 Hz. It does provide a smoother looking plot, but it still has the relatively slow update to the plot. Further increasing the rate of either the sample rate or the update rate seems to be a current limitation for MATLAB Mobile.
%connect to phone and get accel data
clear m
m = mobiledev;
m.AccelerationSensorEnabled = 1;
m.Logging = 1;
%initialize data for rolling plot
data = zeros(200,1);
%initialize plot
figure(1)
p = plot(data);
axis([0 200 -15 15]);
pause(1)
tic
while (toc < 30)%run for 30 secs
%get new z coordinates
[a,~] = accellog(m);
if length(a) > 200
data = a(end-199:end,3);
else
data(1:length(a)) = a(:,3);
end
% redraw plot
p.YData = data;
drawnow
end
Example Plot:
  3 件のコメント
David
David 2023 年 6 月 23 日
This solution does produce a smooth plot at the end of the while-loop.
However I want to display the plot in real time, meaning updating it at the end of the while-loop.
On the Desktop-Version of Matlab this does work. On the Matlab mobile Application, the plot is displayed only after the whole script is run.
Is there any solution or workaround to this problem?
Shivanshu Singh
Shivanshu Singh 2023 年 8 月 28 日
As you have mentioned that you are able to plot realtime data on desktop do you know how to plot real time data of acceleration and position using Matlab Mobile on Desktop.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeIntroduction to Installation and Licensing についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by