# grouping values that as need

2 views (last 30 days)
Nicle Davidson on 5 Nov 2021
Commented: Nicle Davidson on 5 Nov 2021
I hava a csv file with totally random numbers all in one column, that I read from using
this table have 60 values in one column,
I would like to splitt these 60 values into 10 groups in which each of these have 6 of the values. for example the frist group have from 1 ot 6 the second group have from 7 to 12 etc
How can I do that?
*the groups of my numbers should be presented such as:
x1=[the first group of six numbers]
x2=[the second group]
x3=[...];
x4=[...];
x5=[...];
x6=[...];

Sudharsana Iyengar on 5 Nov 2021
Edited: Sudharsana Iyengar on 5 Nov 2021
An example:
x=linspace(1,60,60);
k=1;
for i =1:6:length(x)
B(k,1:6)=x(i:i+5) %; add this semicolon if you dont want this to be printed.
k=k+1;
end
B = 1×6
1 2 3 4 5 6
B = 2×6
1 2 3 4 5 6 7 8 9 10 11 12
B = 3×6
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
B = 4×6
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
B = 5×6
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
B = 6×6
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
B = 7×6
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
B = 8×6
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
B = 9×6
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
B = 10×6
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
A = 1:60;
B = reshape(A,[10,6]) %more easier way
Nicle Davidson on 5 Nov 2021
I appreciate your time and effort and I accept this answer. Thank you