count number with continuous numbers of 1's ?

3 vues (au cours des 30 derniers jours)
MUKESH KUMAR
MUKESH KUMAR le 31 Août 2018
Réponse apportée : Stephen23 le 31 Août 2018
I had a matrix A=[0 0 1 1 1 1 0 0 0 1 1 0 0 1 0 0 1 0 0 0 1 1 1 0 0] like this , now I want a matrix B in which B(3)=1,next B(10)=1,B(14)=1 and similarly B(17)=1,B(21)=1 and rest are zeros means B gets value 1 when A first get 1.

Réponse acceptée

Stephen23
Stephen23 le 31 Août 2018
>> B = [0,diff(A)>0]
B =
0 0 1 0 0 0 0 0 0 1 0 0 0 1 0 0 1 0 0 0 1 0 0 0 0

Plus de réponses (0)

Catégories

En savoir plus sur Operating on Diagonal Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by