# how to take every row in matrix?

1 view (last 30 days)
daniel danish on 10 Nov 2021
Edited: Stephen on 10 Nov 2021
i have matrix 1000x1000. i want collect data at row 2 until 4 , 6 until 8 , 8 until 10 until end

Stephen on 10 Nov 2021
Edited: Stephen on 10 Nov 2021
You could use MAT2CELL, just generate the sizes based on your matrix dimensions and requirements:
A = randi(10,10,10)
A = 10×10
10 7 9 3 9 2 1 10 7 6 9 7 3 2 9 7 10 8 6 8 9 6 5 4 9 10 4 7 1 9 1 9 4 4 1 5 3 2 5 5 10 7 6 8 9 5 2 2 3 6 5 7 6 7 4 1 1 8 10 4 5 4 10 7 10 6 1 6 9 2 7 2 9 6 8 10 8 10 5 9 1 7 8 1 2 8 5 9 5 1 3 7 1 10 10 5 1 5 2 3
C = mat2cell(A(2:end,:),[3,3,3],10)
C = 3×1 cell array
{3×10 double} {3×10 double} {3×10 double}
C{1},C{2},C{3}
ans = 3×10
9 7 3 2 9 7 10 8 6 8 9 6 5 4 9 10 4 7 1 9 1 9 4 4 1 5 3 2 5 5
ans = 3×10
10 7 6 8 9 5 2 2 3 6 5 7 6 7 4 1 1 8 10 4 5 4 10 7 10 6 1 6 9 2
ans = 3×10
7 2 9 6 8 10 8 10 5 9 1 7 8 1 2 8 5 9 5 1 3 7 1 10 10 5 1 5 2 3

KSSV on 10 Nov 2021
Edited: KSSV on 10 Nov 2021
iwant = A(2:2:end,:) ;
daniel danish on 10 Nov 2021
no. it din't answer my question.
for example i have matrix A=randi(10,10,10)
A =
6 6 8 8 5 2 6 5 6 4
5 4 4 3 7 4 8 5 8 6
10 4 5 5 7 7 10 6 5 8
7 4 5 5 1 5 8 4 8 1
8 10 9 5 6 7 9 9 3 1
2 7 3 9 7 3 9 3 2 7
3 3 9 9 2 5 1 3 5 5
8 2 4 8 4 10 10 4 5 2
9 1 5 9 9 6 5 3 3 3
1 1 8 7 8 10 10 2 5 4
i want every 2 row until 4 row until end, which mean like this
B=
5 4 4 3 7 4 8 5 8 6
10 4 5 5 7 7 10 6 5 8
7 4 5 5 1 5 8 4 8 1
C=
8 10 9 5 6 7 9 9 3 1
2 7 3 9 7 3 9 3 2 7
3 3 9 9 2 5 1 3 5 5
and i want to calculate the mean all of that