How can i split the values of vector into group of 5?

12 views (last 30 days)
suppose i have the vector having 50 values values, no i want to split that values in the group of five?
group 1=(first five values)
group 2=(next five values)
.
.
.
The vector i have is
0.6137
0.8946
1.1238
1.5200
2.9336
9.9637
10.3845
10.5308
10.8468
12.0193
16.5591
16.9117
17.0800
17.6835
19.9467
24.6567
24.9646
25.1283
25.5325
26.3262
29.9249
30.1739
30.3119
30.6054
31.4281
34.2383
34.5242
34.6736
35.6291
36.3185
39.1514
39.4394
39.5863
39.9892
40.6942
45.1461
45.3931
45.6263
45.9219
46.6433
49.6028
49.8943
50.0356
50.5986
51.3305
54.3656
54.6409
54.7636
55.0352
57.0281

Answers (1)

James Tursa
James Tursa on 29 Oct 2019
Edited: James Tursa on 29 Oct 2019
Assuming your vector is divisible by 5, you could do this:
v = your vector
g = reshape(v,5,[]); % reshape v into a 5 x N matrix
Then your groups of 5 would be g(:,1), g(:,2), g(:,3), ... etc.
You DO NOT want to have variables named group1, group2, etc. because that is very hard to manage downstream in your code, forcing you to use eval( ) to process them in a loop, etc. For a full discussion of why this is discouraged:

Tags

No tags entered yet.

Community Treasure Hunt

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

Start Hunting!