A=rand(3,4,6);
pattern=[1 1 1 0 0];
[m,n,t]=size(A);
q=floor(t/nnz(pattern));
idx=repmat( reshape(pattern,1,1,[]) , 1,1,q)& true(m,n);
out=zeros(size(idx));
out(idx)=A(1:nnz(idx)),
results in
out(:,:,1) =
0.8147 0.9134 0.2785 0.9649
0.9058 0.6324 0.5469 0.1576
0.1270 0.0975 0.9575 0.9706
out(:,:,2) =
0.9572 0.1419 0.7922 0.0357
0.4854 0.4218 0.9595 0.8491
0.8003 0.9157 0.6557 0.9340
out(:,:,3) =
0.6787 0.3922 0.7060 0.0462
0.7577 0.6555 0.0318 0.0971
0.7431 0.1712 0.2769 0.8235
out(:,:,4) =
0 0 0 0
0 0 0 0
0 0 0 0
out(:,:,5) =
0 0 0 0
0 0 0 0
0 0 0 0
out(:,:,6) =
0.6948 0.0344 0.7655 0.4898
0.3171 0.4387 0.7952 0.4456
0.9502 0.3816 0.1869 0.6463
out(:,:,7) =
0.7094 0.6797 0.1190 0.3404
0.7547 0.6551 0.4984 0.5853
0.2760 0.1626 0.9597 0.2238
out(:,:,8) =
0.7513 0.6991 0.5472 0.2575
0.2551 0.8909 0.1386 0.8407
0.5060 0.9593 0.1493 0.2543
out(:,:,9) =
0 0 0 0
0 0 0 0
0 0 0 0
out(:,:,10) =
0 0 0 0
0 0 0 0
0 0 0 0
Best Answer