How to extract values at particular interval ?

조회 수: 5 (최근 30일)
Aarti Soni
Aarti Soni 2022년 10월 16일
답변: Star Strider 2022년 10월 16일
Hello everyone,
I have a time series matrix (A = 180x360x48) and array (B = 1x48) and I want to extract values at every after 4th interval. In matrix A, the third dimension is time.
Basically, I want to create a new matrix and array which will have only 12 values. e.g., 1,5,9,13,17, 21, 25, 29, 33, 37, 41, 45
Output will be A = 180x360x12, B = 1x12
How can I do this?
Thanks

채택된 답변

Star Strider
Star Strider 2022년 10월 16일
Try something like this —
A = randi(9,3,4,48)
A =
A(:,:,1) = 2 2 7 1 8 8 4 7 7 1 9 9 A(:,:,2) = 5 4 8 9 8 9 7 4 6 8 6 3 A(:,:,3) = 5 6 9 2 1 4 1 7 8 8 9 8 A(:,:,4) = 9 5 9 2 2 6 5 9 8 8 7 5 A(:,:,5) = 4 3 9 4 5 7 1 9 3 1 7 9 A(:,:,6) = 6 1 4 7 9 7 6 2 2 6 6 5 A(:,:,7) = 6 5 6 1 1 5 9 6 5 6 8 9 A(:,:,8) = 1 5 2 9 8 6 7 4 8 7 8 9 A(:,:,9) = 9 9 1 9 4 3 4 2 4 2 4 9 A(:,:,10) = 7 4 8 1 6 7 9 1 8 8 6 9 A(:,:,11) = 5 1 2 4 2 8 8 6 3 7 6 5 A(:,:,12) = 1 5 9 9 9 3 6 1 2 2 3 9 A(:,:,13) = 2 9 5 9 7 6 8 2 6 3 8 4 A(:,:,14) = 8 4 1 2 6 2 3 3 6 2 3 9 A(:,:,15) = 6 4 8 5 2 8 2 9 6 2 9 7 A(:,:,16) = 7 4 9 5 3 3 4 9 6 6 6 5 A(:,:,17) = 4 2 6 5 7 9 9 1 5 4 9 6 A(:,:,18) = 5 7 4 5 3 7 7 1 1 7 5 1 A(:,:,19) = 7 7 8 4 2 1 4 6 1 4 9 9 A(:,:,20) = 5 8 1 7 2 4 9 8 3 5 1 6 A(:,:,21) = 9 5 4 9 4 6 5 8 4 7 4 2 A(:,:,22) = 2 3 9 6 3 3 4 4 1 4 9 6 A(:,:,23) = 3 3 6 8 2 1 9 6 9 3 8 9 A(:,:,24) = 1 1 9 4 5 8 7 3 5 7 2 1 A(:,:,25) = 3 6 7 5 1 3 4 9 4 8 3 7 A(:,:,26) = 8 3 8 1 5 7 5 4 9 2 6 7 A(:,:,27) = 7 5 4 1 3 8 9 5 4 5 5 5 A(:,:,28) = 8 1 1 5 4 7 1 6 8 2 1 4 A(:,:,29) = 7 9 8 9 4 7 1 4 4 8 6 3 A(:,:,30) = 8 1 8 9 4 2 1 9 2 8 3 8 A(:,:,31) = 2 6 3 5 7 7 5 8 8 4 5 4 A(:,:,32) = 9 4 1 2 3 8 4 6 6 8 7 8 A(:,:,33) = 1 7 6 6 9 2 3 2 1 8 1 5 A(:,:,34) = 5 9 1 6 3 7 4 6 7 8 6 8 A(:,:,35) = 6 7 8 5 6 2 2 4 1 6 6 3 A(:,:,36) = 8 8 9 5 1 3 4 5 3 3 4 4 A(:,:,37) = 4 5 3 5 1 6 1 2 6 9 1 6 A(:,:,38) = 9 1 5 7 3 9 8 6 9 7 3 2 A(:,:,39) = 2 1 8 3 2 7 6 3 7 1 4 5 A(:,:,40) = 5 3 8 4 8 9 7 9 6 3 2 2 A(:,:,41) = 6 7 6 2 4 4 8 5 2 1 7 1 A(:,:,42) = 7 2 9 6 5 5 3 8 7 3 6 5 A(:,:,43) = 3 5 2 7 5 5 2 7 4 6 8 2 A(:,:,44) = 1 7 4 6 7 1 4 8 3 1 4 7 A(:,:,45) = 5 2 8 7 4 9 8 5 7 3 3 1 A(:,:,46) = 9 2 1 3 2 1 4 6 6 3 6 5 A(:,:,47) = 3 5 1 7 5 3 7 7 5 8 3 1 A(:,:,48) = 5 5 5 9 3 1 6 4 2 1 3 5
B = randi([11 19], 1, 48)
B = 1×48
15 11 15 17 15 19 15 12 12 18 11 16 13 18 18 14 17 18 18 15 19 14 16 12 18 17 17 16 14 18
iv = 1:4:48 % Index Vector
iv = 1×12
1 5 9 13 17 21 25 29 33 37 41 45
Anew = A(:,:,iv)
Anew =
Anew(:,:,1) = 2 2 7 1 8 8 4 7 7 1 9 9 Anew(:,:,2) = 4 3 9 4 5 7 1 9 3 1 7 9 Anew(:,:,3) = 9 9 1 9 4 3 4 2 4 2 4 9 Anew(:,:,4) = 2 9 5 9 7 6 8 2 6 3 8 4 Anew(:,:,5) = 4 2 6 5 7 9 9 1 5 4 9 6 Anew(:,:,6) = 9 5 4 9 4 6 5 8 4 7 4 2 Anew(:,:,7) = 3 6 7 5 1 3 4 9 4 8 3 7 Anew(:,:,8) = 7 9 8 9 4 7 1 4 4 8 6 3 Anew(:,:,9) = 1 7 6 6 9 2 3 2 1 8 1 5 Anew(:,:,10) = 4 5 3 5 1 6 1 2 6 9 1 6 Anew(:,:,11) = 6 7 6 2 4 4 8 5 2 1 7 1 Anew(:,:,12) = 5 2 8 7 4 9 8 5 7 3 3 1
Bnew = B(iv)
Bnew = 1×12
15 15 12 13 17 19 18 14 17 15 19 15
I limited the ‘A’ matrix row and column dimensions to make the result more understandable. I have no idea what are actually in the matriix or vector.
.

추가 답변 (1개)

Torsten
Torsten 2022년 10월 16일
A = rand(180,360,48);
B = [1,5,9,13,17, 21, 25, 29, 33, 37, 41, 45];
A = A(:,:,B);
size(A)
ans = 1×3
180 360 12

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by