Looping through 3rd dimension
Show older comments
Hi
I am currently working on a project with temperature data. The data is stored in a 128 x 64 x 2160 matrix called T.
I have calculated that summer is between index 30:48 and then +72 for the consecutive summer years.
I want to loop through the third dimension and stored this in a new variable ST.
Please see below code I have already made, i'm not too sure where to go after this.
ST=NaN*ones(128,64,30) %Setting up grid
x=0;
for i=30:48;
x=x+1;
ST(:,:,x) = T(:,:,[i:i]); %Looping through third dimension 30:48
end
ST should essentially be 128 x 64 x 30 or 128 x 64 x 540 matrix
Any help would be great, thank you!
Accepted Answer
More Answers (1)
ST=reshape( T, 128 ,64,72,30);
ST=reshape( ST(:,:,30:48,:), 128, 64,[]);
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!