How to calculate the mean excluding zero voxels

1 回表示 (過去 30 日間)
Gina Carts
Gina Carts 2020 年 4 月 29 日
回答済み: Walter Roberson 2020 年 4 月 29 日
Hi,
I have a mask with different regions marked with values 1,2,3 and 4. The background is zero.
My data have some NaNs so I set those to 0. I then calculated the mean of my regions but in some cases there were NaNs and now are zero. I want to exclude these voxels from my calculation. My code is the following:
blood(isnan(blood))=0;
bloodmean = accumarray(double(mask(:))+1, blood(:), [], @mean)
Can someone help me to exclude the zero voxels from my calculation?

回答 (1 件)

Walter Roberson
Walter Roberson 2020 年 4 月 29 日
Leave the nans as nan, and then
bloodmean = accumarray(double(mask(:))+1, blood(:), [], @nanmean, 0);

カテゴリ

Help Center および File ExchangeImage Segmentation and Analysis についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by