index variable based on time points

1 visualizzazione (ultimi 30 giorni)
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 Commenti
Walter Roberson
Walter Roberson il 5 Dic 2019
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
Raheema Al Karim Damani il 6 Dic 2019
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!

Accedi per commentare.

Risposta accettata

Walter Roberson
Walter Roberson il 5 Dic 2019
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);

Più risposte (0)

Categorie

Scopri di più su MRI in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by