extract data from a 3D matrix using a window
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Mathieu NOE
am 19 Mär. 2025
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 Kommentare
Siehe auch
Kategorien
Mehr zu Workspace Variables and MAT Files finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!