ttest error - undefined variable - error nanmean nanvar etc.

Dear All,
I am trying to perform a simple statistics:
two vectors and a ttest or ttest2.
I have done that before, but now I am getting an error. Ranksum works instead.
e.g.1) ttest(x)
Undefined variable "coder" or class "coder.internal.scalarEg".
Error in nan_sum_or_mean (line 11)
XZERO = coder.internal.scalarEg(x);
Error in nanmean (line 7)
y = nan_sum_or_mean('mean',varargin{:});
Error in ttest (line 131)
xmean = nanmean(x,dim);
e.g.2) ttest2(x,y)
Undefined function or variable 'eml_is_const'.
Error in nanvar (line 29)
coder.internal.assert(eml_is_const(dim), ...
Error in ttest2 (line 169)
s2x = nanvar(x,[],dim);
I found in the forum several suggestions like:
-make sure you have statistics toolbox. I have statistics and machine learning and I re-installed everything from scratch, just to be extra sure.
-make sure you are using "official" functions and I do.
I have no clue as to why it is not working.
I am using matlab 2016b
Can anyone help me figure it out?
Thank you in advance,
Ilaria

2 commentaires

Make it easy for us to help you. Attach your code (in *.m file), and your data (in a *.mat), using the INSERT function (the one that looks like a paper clip) in the toolbar, so that we can reproduce your problem.
Hi cyclist,
there is no code involved here.
I am typing ttest in the command window and making up a couple of vectors.
Does this help?
Ilaria

Connectez-vous pour commenter.

 Réponse acceptée

Walter Roberson
Walter Roberson le 9 Août 2020
Error in nanvar (line 29)
coder.internal.assert(eml_is_const(dim), ...
In R2016b, the release you are using, nanvar has 30 lines of comments and then one line of narginchk and then one line of calling var() with 'omitnan' . There is no coder.internal.assert call in it.
... Not unless one of the following is true:
  1. You are attempting to compile the code using MATLAB Coder which would be important to know for this purpose; OR
  2. You are calling nanmean in Simulink within a MATLAB Function Block, and you have Acceleration turned on or Rapid Acceleration turned on; OR
  3. You have found the files intended to be used for code replacement for nanvar when using MATLAB Coder (or Simulink Coder), and you have put those directories onto your MATLAB Path earlier than the correct directories. If so then restoredefaultpath; rehash toolboxcache;

7 commentaires

Hi Walter,
Thank you for your prompt reply and for this specification.
None of the three points you metion is true.
Please tell me if I understand the issue correctly:
matlab 2016b is not equpped with nanvar, nanmean etc. Is that correct?
Where can I (safely) download them?
Why a matlab toolbox would call a function that does not exists?
Thank you again.
Ilaria
In all releases, nanmean(), nanvar(), are part of the Statistics Toolbox.
But look at the error message:
Error in nanmean (line 7)
y = nan_sum_or_mean('mean',varargin{:});
That line does not exist in nanmean in R2016b -- nor any line similar to it. nanmean contains a narginchk and a call to mean(), and comments. Line 7 of it is
% along the first non-singleton dimension.
You are not using Mathwork's nanmean.
Look at
which -all nanmean
You should see something similar to
MATLAB_R2016b.app/toolbox/stats/stats/nanmean.m
I suspect that you will instead see a nanmean from a third-party toolbox such as FracLab, eeglab, or one of the spm* releases. Whatever you find needs to be moved further down the search path, such as by using pathtool and selecting the directories for the third-party toolbox and using "Move to bottom".
Thanks!!!
I had to remove the additional packages (spm in my case), because I could not send the stats folder up.
But it worked out!
Thank you so much!
:-)
Ilaria
Hi all,
Sorry for disturbing... I met similar question as Sani...
When i am using a plugin in EEGLAB, there is a similar "EEGLAB error in function nan_sum_or_mean() at line 19 Error: undefined function 'eml_is_const' for input argument of type 'double' “
After checking
>> which -all nan_sum_or_mean
D:\matlab_2022b\toolbox\stats\eml\private\nan_sum_or_mean.m % Private to eml
I also tried ”move EEGLAB to bottom“, but still doesn't work.
I really don't know what to do and I can't find any information about "eml_is_const". I would be highly appreciate if you could give me some insights.
Thanks in advance.
the eml directory should not be on your MATLAB path.
You should experiment with
restoredefaultpath; rehash toolboxcache
and then test. If everything still works then
savepath
Hi Walter,
Thanks for your reply!
I experimented with restoredefaultpath and rehash toolboxcache, but still not work...
There is following the results of ver:
MATLAB Version 9.13 (R2022b)
EEGLAB Toolbox to process EEG data Version - see
MATLAB Coder Version 5.5 (R2022b)
Signal Processing Toolbox Version 9.1 (R2022b)
Stateflow Version 10.7 (R2022b)
Statistics and Machine Learning Toolbox Version 12.4 (R2022b)
I suspect whether it is because of my Matlab version or sth...
Problem has been solved after I turned MATLAB from R2022b to 2020a, turned EEGLAB from ver 2023.0 to 2021.0. :)
Thank for your suggestion and patience.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

Community Treasure Hunt

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

Start Hunting!

Translated by