Split an Array in sub-arrays based on the first number in the column
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Fabio Taccaliti
am 19 Apr. 2022
Kommentiert: Stephen23
am 20 Apr. 2022
Hello,
I have an array M 2939x4 that I would like to split in sub-arrays based on the number in the first column.
I mean in the first colunm a number is listed, first 0, then 0.02, then 0.04 and so on (with an increment of 0.02) until 2.2, the problem is that the times that this number appear is not always the same (for example the 0 is on the first 28 rows, the 0.02 in the following 24 and the 0.04 in the next 29).
My idea was to find the number of different number listed in the first column (time) and how many times they occurs (b).
[time,b] = unique(M(:,1));
b = [b; length(M)];
How can I continue it?
Thanks in advance.
0 Kommentare
Akzeptierte Antwort
Stephen23
am 19 Apr. 2022
M = [[0;0.2;0.2;0.4;0.6;0.6;0.6],rand(7,3)]
D = diff(find([1;diff(M(:,1));1]));
C = mat2cell(M,D,4)
C{:}
3 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Antennas, Microphones, and Sonar Transducers 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!