Finding nanmedian of a 3D array.

5 ビュー (過去 30 日間)
Snehalatha
Snehalatha 2015 年 6 月 9 日
コメント済み: Snehalatha 2015 年 6 月 9 日
Hi I have a 3D array and I am trying find the median with nans excluded. I used the nanmedian function but i get the error 'Unexpected MATLAB expression'for the line I have commented out. Could you tell me why? How can i make it right?
for i=1:size(tempBeforeDelam,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)
%
% beforeDelam(m,n)= nanmedian[tempBeforeDelam(i,j,1) tempBeforeDelam(i,j,2) tempBeforeDelam(i,j,3) tempBeforeDelam(i,j,4) tempBeforeDelam(i,j,5)]
%
end
end
end
  1 件のコメント
per isakson
per isakson 2015 年 6 月 9 日
編集済み: per isakson 2015 年 6 月 9 日

サインインしてコメントする。

採用された回答

Sean de Wolski
Sean de Wolski 2015 年 6 月 9 日
You have brackets [] instead of parenthesis ()
This should do it; you can use 1:5 and take nanmedian along third dimension to avoid unrolling the pieces:
beforeDelam(m,n)= nanmedian(tempBeforeDelam(i,j,1:5),3)
Also note that in 15a, median now has an 'omitnan' flag so you can use it instead.
median(tempBeforeDelam(i,j,1:5),3,'omitnan')
  1 件のコメント
Snehalatha
Snehalatha 2015 年 6 月 9 日
Hey I tried omitnan it doesnt work for me because i have 2014b version.
I have one more question. If I want to use the same nanmedian to find out median of i and j through the 5 sheets would i write as follows?
%gives median for column1 over the 5 sheets
beforeDelam(m,n)= nanmedian(tempBeforeDelam(i,j,1:5),1);
n=n+1;
%gives median for column2 over the 5 sheets
beforeDelam(m,n)= nanmedian(tempBeforeDelam(i,j,1:5),2);
n=n+1;
%gives median for column3 over the 5 sheets
beforeDelam(m,n)= nanmedian(tempBeforeDelam(i,j,1:5),3);
I get the following error if i try to run the above code
Assignment has more non-singleton rhs dimensions than non-singleton subscripts
Error in loadfile (line 29)
beforeDelam(m,n)= nanmedian(tempBeforeDelam(i,j,1:5),1);

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Distribution Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by