How can I classify data in and print it, all in real time?

조회 수: 4 (최근 30일)
Netanel Zadok
Netanel Zadok 2018년 8월 30일
편집: Netanel Zadok 2018년 8월 30일
My code is based on an answer I saw here.
I'm using mobile matlab app and I'm trying to classify the Azimuth sensor to 3 groups: left, middle and right- based on the Azimuth value. However, when I'm trying to print it after classification using drawnow, the plot ignores it and shows the actual value, not the classification.
%connect to phone and get accel data
clear
clc
clear m
m = mobiledev;
m.AngularVelocitySensorEnabled = 1;
m.OrientationSensorEnabled = 1;
m.Logging = 1;
%initialize data for rolling plot
zvel = zeros(2000,1);
Azimuth= zeros(2000,1);
%initialize plot
figure(1)
hold on
p = plot(zvel);
p1=plot(Azimuth);
axis([0 200 -30 30]);
pause(1)
i=1;
while (m.Logging ==1 ) %runs until manual stop
[av,~] = angvellog(m);
[o,~] = orientlog(m);
if length(av) > 200
zvel = av(end-199:end,1);
else
zvel(1:length(av)) = av(:,1);
end
if length(o) > 200
Azimuth = o(end-199:end,1)+135;
%added 135 because idle azimuth=-135, and I wanted it to be around zero.
else
Azimuth(1:length(o)) = o(:,1)+135;
end
% redraw plot
if (Azimuth(i)<=20 && Azimuth(i)>-20)
Azimuth(i)= 0; %middle
elseif (Azimuth(i)<=90 && Azimuth(i)>20)
Azimuth(i) = 10; %right
elseif (Azimuth(i)<=-20 && Azimuth(i)>-90)
Azimuth(i) = -10; %left
end
p.YData = zvel;
p1.YData=Azimuth;
drawnow
i=i+1;
end
hold off
I'm not an expert so I guess things here could be a lot better. However, solving the problem I mentioned is my main concern.
Thanks,
Netanel

답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics Performance에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by