Zscore a matrix with NaN
117 ビュー (過去 30 日間)
I have matrix A, and I need to find a zscore value (with the intention of running a PCA) of a matrix that has NaN values. I need to have matlab ignore the NaNs while solving for the zscore value. How can I do this? I tried Zscore = zscore(~isnan(A)) but it didn't work.
Thanks for your help!
Star Strider 2015 年 10 月 19 日
編集済み: Star Strider 2015 年 10 月 19 日
You can create your own function to compute the Z-scores omitting NaN values (I believe the 'omitnan' option began in R2014b). The result vector retains the NaN values while it computes the Z-score without them:
zscor_xnan = @(x) bsxfun(@rdivide, bsxfun(@minus, x, mean(x,'omitnan')), std(x, 'omitnan'));
q = rand(10,2);
q([3 5 7],1) = NaN;
Zscore = zscor_xnan(q);