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

4 visualizaciones (últimos 30 días)
Netanel Zadok
Netanel Zadok el 30 de Ag. de 2018
Editada: Netanel Zadok el 30 de Ag. de 2018
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

Respuestas (0)

Categorías

Más información sobre Graphics Performance en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by