Making consecutive 1s and 0s as a seperate element
Mostra commenti meno recenti
If I have a cell say a= [1 0 0 0 1 1 1 1 0 1] I want b= [ 1,0 0 0, 1 1 1 1,0,1]
2 Commenti
Sudhakar Shinde
il 17 Ott 2020
When you create vector in matlab, two elements of vector are separated by comma (,) or space. Meaning of both are same.
Jetty Rakesh Aditya
il 17 Ott 2020
Risposta accettata
Più risposte (2)
KSSV
il 17 Ott 2020
0 voti
a = [1 0 0 0 1 1 1 1 0 1];
consecGroups = findgroups(cumsum([true, diff(a)~=0]));
b = arrayfun(@(g){a(consecGroups==g)},1:max(consecGroups));
% Show results
celldisp(b)
1 Commento
Jetty Rakesh Aditya
il 17 Ott 2020
Categorie
Scopri di più su Matrices and Arrays in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!