extract values from a vector for 5 secs every time
조회 수: 1 (최근 30일)
이전 댓글 표시
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
답변 (2개)
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)
댓글 수: 0
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);
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Install Products에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!