Accessing alternate rows and columns in the matrix.
30 views (last 30 days)
Show older comments
Permvir Singh
on 26 Aug 2022
Commented: Star Strider
on 26 Aug 2022
A =
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
How can I access alternate rows and columns e.g. 1st & third row and 2nd & 4th column from the above matrix?
0 Comments
Accepted Answer
Star Strider
on 26 Aug 2022
Edited: Star Strider
on 26 Aug 2022
Try this —
A = [ 1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16];
Rows = A(1:2:end,:)
Columns = A(:,2:2:end)
Both = A(1:2:end, 2:2:end)
EDIT — (26 Aug 2022 at 12:22)
Corrected typographical error.
.
2 Comments
Star Strider
on 26 Aug 2022
It works here with the supplied ‘A’ matrix.
I am not certain what matrix you are working with if it is different from ‘A’ here. It could be a problem with the size of the matrix and the ability of whatever you are using to display all the numbers.
More Answers (0)
See Also
Categories
Find more on Matrices and Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!