Looping through a 3D matrix with third dimension data grouping

hy everyone, i new to matlab. i use matlab 2013a. my problem is not understanding in making programs in the form of looping functions for 3D matrix 144,12,855
I want to run the following code such that it performs the function element by element through the 3rd dimension (but does not use all 855 points). I have grouped the data. I want this to be done for every pixel giving me 1728 outputs (144*12).
%Average the data against latitude to be 3D
angin_o1 = squeeze(mean(angin_o(1:144,31:43,1:12,1:855),2));
% classify strong el nino years
a=squeeze(mean(angin_o1(:,:,37:48),3));
b=squeeze(mean(angin_o1(:,109:120),3));
c=squeeze(mean(angin_o1(:,181:192),3));
d=squeeze(mean(angin_o1(:,205:216),3));
e=squeeze(mean(angin_o1(:,217:228),3));
f=squeeze(mean(angin_o1(:,289:300),3));
g=squeeze(mean(angin_o1(:,409:420),3));
h=squeeze(mean(angin_o1(:,421:432),3));
i=squeeze(mean(angin_o1(:,469:480),3));
j=squeeze(mean(angin_o1(:,529:540),3));
k=squeeze(mean(angin_o1(:,589:600),3));
l=squeeze(mean(angin_o1(:,601:612),3));
m=squeeze(mean(angin_o1(:,805:816),3));
n=squeeze(mean(angin_o1(:,817:828),3));
for r=1:1:length(lon(:));
for s=1:1:length(y);
o=a(:,1:1:12);
for t=1:1:length(o);
% dlmwrite(a,y,u)
end
end
end
and I don't really understand about using the loop function for 3-dimensional matrices. Thank you for the help.

3 Comments

If you would back up and describe the problem you're trying to solve and what the initial data are, would probably get more useful suggestions...trying to decipher and modify code alone (particularly code that doesn't do what is wanted) is hard.
It is generally a sign the data storage isn't optimal when start to create multiple variables that are essentially identical with the exception of indexing as you have above with a:n -- all those could be placed into a loop structure if the particular indices were in the form of an indexing array. And, even better would be to use a reference to the underlying values (years, I'd guess?) inside the original array and a lookup for those instead of hardcoding "magic" numbers into the function making it totally specific to the one data set.
If you want to loop through third dimension:
for i = 1:n
angin_o1(1,1,i) % select (1,1,i) element
end
Is that your question?
I plot the x and y axes, which are longitude and height (144 * 12) to the average wind value (a to n)

Sign in to comment.

Answers (0)

Tags

Asked:

on 3 Aug 2019

Commented:

on 5 Aug 2019

Community Treasure Hunt

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

Start Hunting!