Grouping elements by conditions
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Amro Lulu
am 21 Aug. 2018
Kommentiert: dani elias
am 19 Nov. 2020
I have an array [ 1 1.2 1.5 1.9 5 8 8.1 10 12 12.3 12.5]. I'm trying to group the elements that are within a window of length 1, so I get [ 1 1.2 1.5 1.9] [8 8.1] [12.3 12.5] How can this be done efficiently
2 Kommentare
dani elias
am 19 Nov. 2020
how can I use the same concept to group every 4 binary digit, for the case I have an array of 256 binary number,
example
a=[1 1 1 1 1 1 1 1 1 0 1 1 1 0 0 0];
to be in a form of
b=[1111;1111;1011;1000]
Akzeptierte Antwort
Matt J
am 21 Aug. 2018
Bearbeitet: Matt J
am 21 Aug. 2018
x=[ 1 1.2 1.5 1.9 5 8 8.1 10 12 12.3 12.5];
label = graph_connected_components(abs(x.'-x)<=1)
groupcell = splitapply(@(g){g},x,label)
5 Kommentare
Matt J
am 29 Aug. 2018
Adapting Yuvaraj's answer,
x=[ 1 1.2 1.5 1.9 5 8 8.1 10 12 12.3 12.5; 1 5.3 2.1 5.4 1 6 2.1 45 23 14.3 13.4];
a=x(1,:);
Len=diff([0,find(diff(a)>1),numel(a)]);
S=mat2cell(x,2,Len)
Weitere Antworten (1)
Yuvaraj Venkataswamy
am 21 Aug. 2018
Bearbeitet: Matt J
am 21 Aug. 2018
This is your answer.
X=[ 1 1.2 1.5 1.9 5 8 8.1 10 12 12.3 12.5];
Len=diff([0,find(diff(a)>1),numel(a)]);
S=mat2cell(X,1,Len);
0 Kommentare
Siehe auch
Kategorien
Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!