how to calculate mean without considering the zero in matrix

5 ビュー (過去 30 日間)
ImageAnalyst
ImageAnalyst 2020 年 5 月 19 日
回答済み: the cyclist 2020 年 5 月 19 日
I want to calculate MSE of two frames. I am ignoring the nan values by creating a mask associated to the motion compensated frame which has 1 wherever there is a non nan value in mcframe and 0 wherever there is nan. When I caluculate the MSE i only want to caluclate the error where mask is 1. I am using the following code but the value i am getting is pretty high. Not sure if I am doing the right thing here.
Attached are the values of mask, diff and mcframe matrices
mcframe(isnan(mcframe)) = 0;
diff = (mcframe - double(current_pic)).^2;
mse = sum(sum(diff))./sum(sum(mask == 1));
  1 件のコメント
the cyclist
the cyclist 2020 年 5 月 19 日
FYI, it would be much easier for us if you had saved those variables to a *.mat file, and uploaded that.

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

回答 (1 件)

the cyclist
the cyclist 2020 年 5 月 19 日
Presumably the easiest way to do what you want is to use the nanmean function from the Statistics and Machine Learning Toolbox, or the 'omitnan' input to the mean function.

カテゴリ

Help Center および File ExchangeIntroduction to Installation and Licensing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by