How do I implement a sliding window technique to initialize a large matrix?
조회 수: 1 (최근 30일)
이전 댓글 표시
I need to initialize a large 5 Dimensional Matrix. I am unable to initialize the whole matrix at once as I run out of memory. How can I implement a sliding window technique to initialize a small part of the matrix and then slide along one direction to gradually add the remaining elements?
채택된 답변
MathWorks Support Team
2009년 6월 27일
The following example shows how to implement a sliding window approach to initialize a large matrix.
The required matrix is a 5-D matrix which is 1000x6x4x3x6. We can initially initialize a 50x6x4x3x6 matrix and then slide along the 1st dimension to add the remaining 9950x6x4x3x6 elements
function sliding_matrix
clear
countMatrix = zeros(50, 6, 4, 3, 6); %initialize a small matrix
for t = 1 : 50
for bm =1 : 6 % 5 bm
for bw =1 : 4 % 4 bw
for lv = 1 : 3 % 5 lv
for ta=1 : 6 % 200 ta
countMatrix(t,bm,bw,lv,ta) = ceil(101*rand(1)); %initialze the values
end
end
end
end
end
%
% perform necessary operations on the matrix
%
for i = 1:9950 %slde the window 10 times
%call function to add new data
countMatrix = SlideMatrix(countMatrix, i);
%
% perform necessary operations on the matrix
%
end
end
function A = SlideMatrix(A, i)
A(1,:,:,:,:) = []; %Reduce the the first dimension by 1
for bm = 1:6
for bw = 1:4
for lv = 1:3
for ta = 1:6
A(50, bm, bw, lv, ta) = i; %add a new elements along the first dimension
i = i + 1;
end
end
end
end
end
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!