3D array of indices of a 4D array

Hello everyone. I'm new to this forum.
I want to mask a 3D volume that changes over time (i.e. a 4D array) with a 3D binary mask, where 1 are in the positions that I want to keep and 0 the positions that I'm not interested in. Visually, they look more or less like this:
What I was trying is this:
% ´V´ is a width x height x depth x timePoints array, and ´mask´ is a width x height x depth array.
maskTime = repmat(mask,[1 1 1 timePoints]); % Repeat mask over time (size(maskTime) = width x height x depth x timePoints)
[X,Y,Z,T] = ind2sub(size(maskTime),find(maskTime==1)); % X,Y,Z and T are the positions in every dimension where there's a 1
maskedVolume = V(X,Y,Z,T);
However, when I run the code, I get the error: 'Requested array exceeds the maximum possible variable size.'
In my case, I have that the variables ´X´,´Y´, ´Z´ and ´T´ are:
And they contain all the indices where there's a 1. For example, in the case ´X´:
Here, we can see all the indices. Do you know how to fix this problem? I'm interested in avoiding for loops.
Thank you in advance.

댓글 수: 1

Asvin Kumar
Asvin Kumar 2021년 1월 5일
Could you share a minimum working example which reproduces your error?

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

답변 (1개)

Matt J
Matt J 2021년 1월 5일
편집: Matt J 2021년 1월 5일

0 개 추천

It should be sufficient just to do
maskTime=logical(maskedTime);
maskedVolume=V.*maskTime;
or possibly you were looking for
maskTime=logical(maskedTime);
maskedVolume=reshape(V,[],timePoints);
maskedVolume=maskedVolume(maskTime,:);

카테고리

도움말 센터File Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기

질문:

2020년 12월 29일

편집:

2021년 1월 5일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by