extract values from a vector for 5 secs every time

1 vue (au cours des 30 derniers jours)
Amit Pandey
Amit Pandey le 25 Oct 2018
Modifié(e) : Kevin Chng le 26 Oct 2018
i have 2 vectors. Time (sec) = [1 2 3 4 5 6 7 ...... 1000] and Alarm_active =[0 0 1 1 1 1 0 0 0 1 1 1 0..etc]. basically when Alarm is active it reads 1 and when it goes off it reads 0. i want to create a new vector from the Alarm_active which only accounts for Alarm_active for 5 seconds only. i.e. if Alarm went active(1) at time=240 sec and remained active until time=265 secs, then my new vector should only report Alarm_active (1) from time=240 to 245 sec and then go to 0 until 265 sec. it should check this every time the Alarm_active goes to 1
  4 commentaires
Amit Pandey
Amit Pandey le 26 Oct 2018
sorry Kevin, if i am not clear. let me give an example to my question - time = [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20] Alarm_active =[1 1 1 1 0 0 0 1 1 1 1 1 1 0 0 0 0 1 1 1] so i want to create a vector which account for only 2 sec of Alarm_active. so my new vector (Alarm_active_2sec) would be - Alarm_active_2sec =[1 1 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 1 1 0]; so when ever Alarm_active goes 1, alarm_active_2sec goes 1 for only 2 sec. hope i make myself clear. thanks for your response.
madhan ravi
madhan ravi le 26 Oct 2018
no logic is discernible ,more elaboration please?

Connectez-vous pour commenter.

Réponses (2)

KSSV
KSSV le 26 Oct 2018
t = [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20] ;
A =[1 1 1 1 0 0 0 1 1 1 1 1 1 0 0 0 0 1 1 1] ;
% Resahpe for evry two secs
t = reshape(t,2,[])' ;
A = reshape(A,2,[])' ;
% GEt alaram active for 2 secs
AC = sum(A,2)
idx = AC~=0 ;
t_active = t(idx)

Kevin Chng
Kevin Chng le 26 Oct 2018
Modifié(e) : Kevin Chng le 26 Oct 2018
Hi Amit Pandrey,
if let say you want to get the result of every 2 seconds from Alarm_active.
time = [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20];
Alarm_active =[1 1 1 1 0 0 0 1 1 1 1 1 1 0 0 0 0 1 1 1];
timeinterval = 2 %2seconds;
t= time(1:timeinterval:end);
a= Alarm_active(1:timeinterval:end);
result = table(t',a');
result.Properties.VariableNames = {'Time','Alarm_Condition'}
if let say you don't want start from 1st second, want to start from 2nd second, then change 1 to 2.
t= time(2:timeinterval:end);
a= Alarm_active(2:timeinterval:end);

Catégories

En savoir plus sur Install Products dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by