index variable based on time points

1 次查看(过去 30 天)
i have a variable with 1400 images stored in it. I want to index this loop into 40 time points, (so there are 40 variables each containing 35 frames)
mri % 128 x 128 x 1400 uint16
I am trying to build a loop that for each instance in the loop (t = 40), 35 frames are stored into an output variable so essentially at the end I could have an output variable which is
output % 128 x 128 x 35 frames x 40 timepoints
%here is the rudimentary code that I am working from to build into a for loop
perf_0 = mri(:,:,1:35);
perf_1 = mri(:,:,36:70);
perf_2 = mri(:,:,71:105);
perf_3 = mri(:,:,106:140);
perf_4 = mri(:,:,141:175);
perf_5 = mri(:,:,176:210);
perf_6 = mri(:,:,211:245);
  4 个评论
Walter Roberson
Walter Roberson 2019-12-5
i = mri(:,:,1:35)
Are the values inside the mri array indices? Because you have
mri8807081(:,:,i+1)
where i is the results you pulled out of mri, so the mri values would have to be indices.
Your loop only uses t for output, so it is going to do the same calculation for each iteration and all of the output() values would come out the same along the 4th dimension. If that is your intent then you should consider only doing the calculation once and repmat() it .
Your original question talks about extracting portions of the variable mri, but here you are extracting portions of the variable mri8807081 using the portions of mri as indices.
Raheema Al Karim Damani
apologies for the confusion, no my intent is what I mentioned earlier to extract segments of the mri variable, basically for first iteration it should index the first 35 frames, the second iteration, the next 35 frames. I think i figured out my query, thank you for your help!

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2019-12-5
output = zeros(size(mri,1), size(mri,2), 35, 40, class(mri));
for t = 1 : 40
output(:,:,:,t) = mri(:,:,35*(t-1) + (1:35));
end
However if this was your purpose then just use
output = reshape(mri, size(mri,1), size(mri,2), 35, 40);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MRI 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by