필터 지우기
필터 지우기

Repeat each page of 3d matrix 24 times

조회 수: 3 (최근 30일)
Grant
Grant 2013년 4월 29일
So as part of a script I have:
totmelt(:,:,day)=daymelt2;
Daymelt2 is a 2d matrix, and day is the day of the year (1:365). As it stands I get a 3d matrix with 365 in the 3rd dimension, or 365 pages. But I need the output for each day to be repeated 24times in consecutive pages. So the first 24 pages are the first daymelt2 matrix, the next 24 the the second daymelt2 matrix.
Is there a way I can do this? Without post-processing by extracting every single page and using repmat.
Thank you
  댓글 수: 2
Walter Roberson
Walter Roberson 2013년 4월 29일
So you want the output to be size(daymelt2,1) x size(daymelt2,2) x 365 x 24 ? Or size(daymelt2,1) x size(daymelt2,2) x (365*24) ?
Grant
Grant 2013년 4월 29일
Currently my output is 420 x 540 x 365. I want it to be 420 x 540 x 8760 - with pages 1:24 being repeats of orignal page 1, 25:48 being repeats of orignal page 2, and so on.
(It probably won't be 365 as my computer won't handle it, but for sake of discussion don't see should make difference. - could be 10 pages becoming 240)
Thanks

댓글을 달려면 로그인하십시오.

채택된 답변

Jan
Jan 2013년 4월 29일
Perhaps you want:
totmelt = repmat(daymelt2, 1, 1, 24*365);
Or:
totmelt = zeros(M, N, 24, 365); % With matchin M and N
...
totmelt(:, :, :, day) = repmat(daymelt2, 1, 1, 24);
...
totmelt = reshape(totmelt, M, N, 24*365);
  댓글 수: 2
Bård Skaflestad
Bård Skaflestad 2013년 4월 29일
As you only need to repeat each page a fixed (and equal) number of times, you can also do something like this:
totmelt = % construct as normal
p = reshape(repmat(1:365, [24, 1]), [], 1);
totmelt = totmelt(:,:,p);
Grant
Grant 2013년 4월 29일
I think this has done what I want Bard, thank you.
And thanks all.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Andrei Bobrov
Andrei Bobrov 2013년 4월 29일
out = totmelt( :,:,kron(1:size(totmelt,2), ones(1,24)) );

카테고리

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