Problem with variable 'nanmean'.

108 views (last 30 days)
mehra
mehra on 19 May 2023
Commented: Rik on 19 May 2023
Hello
In my matlab script I was using 2 function scripts for despiking the data without any problem but nos I have problem with these functions and I get the error
Unrecognized function or variable 'nanmean'.
How can I solve it ?
This is my code and I also attach the func_despike_phasespace3d( ur(:,np),8, 2) data here.
the only different thing is that I am using a different version of matlab 2022b now.
clear,
close all;
clc;
%% Clear Water Mean (Q1S1)
% >>>>> 1mm VectrinoData.342.22.Vectrino Profiler.00000
% >>>>> 2mm VectrinoData.325.22.Vectrino Profiler.00000
% >>>>> 3mm VectrinoData.340.22.Vectrino Profiler.00000
%% 1mm (Sand A) here load the clear water data
load('VectrinoData.342.22.Vectrino Profiler.00000.mat')
ur=Data.Profiles_VelX;
vr=Data.Profiles_VelY;
w1r=Data.Profiles_VelZ1;
w2r=Data.Profiles_VelZ2;
k=length(Data.Profiles_TimeStamp);
% z=0.029:-0.002:0; % Starts from
% z=0:0.002:0.029; % Starts from
Q1S1_1mm=zeros(11,15);
for np=1:15
[u(:,np),ip1] = func_despike_phasespace3d( ur(:,np),8, 2);
[v(:,np), ip2] = func_despike_phasespace3d( vr(:,np),8, 2);
[w1(:,np), ip3] = func_despike_phasespace3d( w1r(:,np), 8, 2);
[w2(:,np), ip4] = func_despike_phasespace3d( w2r(:,np), 8, 2);
w(:,np)=(w1(:,np)+w2(:,np))/2;
Q1S1_1mm(1,np)=0.08-0.0450-(0.002*np);
Q1S1_1mm(2,np)=mean(u(:,np));
Q1S1_1mm(3,np)=mean(v(:,np));
Q1S1_1mm(4,np)=mean(w(:,np));
Q1S1_1mm(5,np)=std(u(:,np));
Q1S1_1mm(6,np)=std(v(:,np));
Q1S1_1mm(7,np)=std(w(:,np));
Q1S1_1mm(8,np)=0.5*( (var(u(:,np))) + var((v(:,np))) + var ((w(:,np))) ); %TKE
Q1S1_1mm(9,np)=mean( (u(:,np)-mean(u(:,np))).* (v(:,np)-mean(v(:,np))) ); %Reynolds shear stress u'v'
Q1S1_1mm(10,np)=mean( (u(:,np)-mean(u(:,np))).* (w(:,np)-mean(w(:,np))) ); %Reynolds shear stress u'w'
Q1S1_1mm(11,np)=mean( (w(:,np)-mean(w(:,np))).* (v(:,np)-mean(v(:,np))) ); % Reynolds shear stress w'v'
end
Q1S1_1mm=sortrows(transpose(Q1S1_1mm));

Answers (2)

KSSV
KSSV on 19 May 2023
Use mean
mean(data,'omitnan')
  2 Comments
mehra
mehra on 19 May 2023
where should I use that ? inside the func_deskpike code?
KSSV
KSSV on 19 May 2023
Where ever you have used nanmean, replace them with the given line.

Sign in to comment.


Dyuman Joshi
Dyuman Joshi on 19 May 2023
nanmean is a part of the "Statistics and Machine Learning Toolbox", which I believe you do not have and which is why you get the error. Additionally the use of nanmean() is not recommended (as you can see in the webpage linked).
Replace all instances of
nanmean(xyz)
with
mean(xyz, 'omitnan')
in both the functions.
  2 Comments
mehra
mehra on 19 May 2023
so is it because ı have not installed it? actually I runned the following command to check (it was provided in answer to a question in mathworks)
license('test','Statistics_Toolbox')
and ans was 1.
so does it mean I have it?
And can I install it or ı should uninstall and install matlab again?
thanks
Rik
Rik on 19 May 2023
Why would you bother? Just do this replacement. It will take you a minute to do, and the error will disappear.
You can even do this (although I wouldn't recommend it):
x = nanmean([1 NaN 3])
x = 2
function varargout=nanmean(varargin)
varargout = cell(1,nargout);
[varargout{:}] = mean(varargin{:},'omitnan');
end

Sign in to comment.

Categories

Find more on Stress and Strain in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!