Hello,
I'm having trouble trying to get certain matrix columns. Let's say I have Matrix A:
A = [1 2 3 4 5 6 7 8 9 10 11 12; 13 14 15 16 17 18 19 20 21 22 23 24]
Let's say I'd like to get every third value starting in position 1. Then I would use this code:
A(:,1:3:end)
My issue is that I'd like to skip four positions and get the next two. This would be my output if I started from the first position:
Output = [1 2 7 8; 13 14 19 20]
I could get every column manually but since I'm working with big matrixes and different sizes it woldn't be convininient.
Can someone come around a solution for this?
Thnak you in advance,
Santos

 채택된 답변

Stephan
Stephan 2021년 4월 21일
편집: Stephan 2021년 4월 21일

1 개 추천

A = [1 2 3 4 5 6 7 8 9 10 11 12; 13 14 15 16 17 18 19 20 21 22 23 24]
A = 2×12
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
A1 = reshape(A',2,[])
A1 = 2×12
1 3 5 7 9 11 13 15 17 19 21 23 2 4 6 8 10 12 14 16 18 20 22 24
b = A1(:,1:3:end)
b = 2×4
1 7 13 19 2 8 14 20
b = b(:)'
b = 1×8
1 2 7 8 13 14 19 20

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by