extract values from a vector for 5 secs every time
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (2)
KSSV
am 26 Okt. 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)
0 Kommentare
Kevin Chng
am 26 Okt. 2018
Bearbeitet: Kevin Chng
am 26 Okt. 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);
0 Kommentare
Siehe auch
Kategorien
Mehr zu Install Products finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!