Code: Select all

```
nanix = isnan(X);
nx = sum(~nanix); % count the number of non-NaN values in each column for calculating mean
X(nanix) = 0;
X = bsxfun(@minus, X, sum(X)./nx);
X(nanix) = 0;
xnorm = sqrt(sum(X.^2));
```

===============

As requested, a test function can be:

Code: Select all

```
%%
function test
a = randn(80,3000);
[r,c] = size(a);
b = randperm(r*c);
nanix = b(1:round(numel(b)*0.3)); % randomly select 30% of values to be NaN
a(nanix) = NaN;
nnx = sum(~isnan(a));
tic;
for i = 1:1000
t=a;
t(nanix)=0;
tm = sum(t)./nnx;
t = bsxfun(@minus, t, tm);
t(nanix) = 0;
tnorm = sqrt(sum(t.^2));
end
tt = toc;
fprintf('time: %.4f',tt);
end
```

Code: Select all

```
>> test
time: 3.4734
```