finding median along the third dimension of a 3d array
Show older comments
Hi everyone, I have the following code to find the median of every cell along the 3rd dimension. My program works for column 3 but not for other two. Can someone tell me why? My code is
m=1;
for i=1:size(tempBeforeDelam,1)
n=1;
for j=1:size(tempBeforeDelam,2)
if(abs((tempBeforeDelam(i,j,1)-tempBeforeDelam(i,j,2)))< 1 && ...
abs((tempBeforeDelam(i,j,2)-tempBeforeDelam(i,j,3))) < 1 && ...
abs((tempBeforeDelam(i,j,3)-tempBeforeDelam(i,j,4))) < 1 && ...
abs((tempBeforeDelam(i,j,4)-tempBeforeDelam(i,j,5))) < 1 && ...
abs((tempBeforeDelam(i,j,5)-tempBeforeDelam(i,j,1))) < 1)
for k=1:5
beforeDelam(m,n)= nanmedian(tempBeforeDelam(i,j,k),3);
n=n+1;
beforeDelam(m,n)= nanmedian(tempBeforeDelam(i,j,k),3);
n=n+1;
beforeDelam(m,n)= nanmedian(tempBeforeDelam(i,j,1:5),3);
m=m+1;
end
end
end
end
5 Comments
Walter Roberson
on 10 Jun 2015
Note: your "if" can be replaced by
if all( abs( diff([tempBeforeDelam(i,j,:), tempBeforeDelam(i,j,1)]) ) < 1)
Snehalatha
on 15 Jun 2015
Walter Roberson
on 15 Jun 2015
if all( abs( diff([ squeeze(tempBeforeDelam(i,j,:)); tempBeforeDelam(i,j,1) ]) ) < 1)
Snehalatha
on 17 Jun 2015
Snehalatha
on 20 Jun 2015
Accepted Answer
More Answers (0)
Categories
Find more on Matrices and Arrays 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!