extract values from a vector for 5 secs every time

조회 수: 1 (최근 30일)
Amit Pandey
Amit Pandey 2018년 10월 25일
편집: Kevin Chng 2018년 10월 26일
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
Amit Pandey
Amit Pandey 2018년 10월 26일
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 2018년 10월 26일
no logic is discernible ,more elaboration please?

댓글을 달려면 로그인하십시오.

답변 (2개)

KSSV
KSSV 2018년 10월 26일
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 2018년 10월 26일
편집: Kevin Chng 2018년 10월 26일
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);

카테고리

Help CenterFile Exchange에서 String Parsing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by