extract data from a 3D matrix using a window
조회 수: 5 (최근 30일)
이전 댓글 표시
I'd like to extract data along the 3rd dimension of a 3D matrix with the size of 2*2*10 using a window with a fixed size but a variable start indeces. But it doesn't work.
Script:
clc; clear;
a = 1:10; % 1*10 vector
J = reshape(repelem(a,2,2),2,2,length(a)); % expand a to 2*2*10 matrix
wsize = 5; % window size
startInd = [1,2;3,4]; % start index of the window
Q = J(:,:,startInd:startInd+wsize); % cannot extract accurately !!!
댓글 수: 0
답변 (1개)
Mathieu NOE
2025년 3월 19일
hello
there is one Q array per startInd value so either you use Q in a for loop without indexing (if you can tolerate to overwrite Q at each iteration, or store each result separately as shown below :
and also correct startInd dimensions as it should be a 1D vector
a = 1:10; % 1*10 vector
J = reshape(repelem(a,2,2),2,2,length(a)); % expand a to 2*2*10 matrix
wsize = 5; % window size
startInd = [1 2 3 4]; % start index of the window
for k = 1:numel(startInd)
disp(['-- Iteration index k = ' num2str(k) '--'])
Q = J(:,:,startInd(k):startInd(k)+wsize) % yes you can
% if you want to store each result separately
Qstore{k} = Q;
end
Qstore{k}
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Workspace Variables and MAT-Files에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!