finding median along the third dimension of a 3d array

6 visualizaciones (últimos 30 días)
Snehalatha
Snehalatha el 10 de Jun. de 2015
Comentada: Snehalatha el 20 de Jun. de 2015
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 comentarios
Snehalatha
Snehalatha el 17 de Jun. de 2015
Hey thx this works :)
Snehalatha
Snehalatha el 20 de Jun. de 2015
Hi Walter, i have a question. How can i modify the above if statement so that the loop goes on if the value is less than 1 or a nan?? looking forward to your help.

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 10 de Jun. de 2015
nanmedian(tempBeforeDelam(i,j,k),3) with fixed i, j, k, is taking nanmedian() of a scalar. It doesn't matter which dimension is used, the result is going to be the scalar.
nanmedian(tempBeforeDelam(i,j,1:5),3) should work for the third dimension.
For nanmedian to be useful on any particular dimension, there must be multiple elements along that dimension. For example,
nanmedian(tempBeforeDelam(i,:,k),2)

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by