I have this vector that I'm trying to iterate over and have a running count for specific elements. I thought about doing this with indexing as well like "find(diff([arr; -1]" as another example. How can I do this so I get this output for this sample array:
arr = [0; 0; 0; 1; 1; 1; 0];
tokenizeSignal(arr)
ans =
3 0
3 1
1 0
A new row is made for each new token. It keeps a count of the number of 0s and 1s in the vector.

댓글 수: 1

dpb
dpb 2016년 11월 6일
There's a runs-finding tool at File Exchange...

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

 채택된 답변

KSSV
KSSV 2016년 11월 7일

0 개 추천

clc; clear all ;
arr = [0; 0; 0; 1; 1; 1; 0];
idx = [find(diff([-1 ; arr ; -1]) ~= 0)] ;
lengths = diff(idx) ;
ele = arr(idx(1:end-1)) ;
iwant = [lengths ele]

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

질문:

2016년 11월 6일

답변:

2016년 11월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by