ttest Matlab R2016b does not work properly
Afficher commentaires plus anciens
Here the code given by mathworks help for the ttest function in R2016b https://www.mathworks.com/help/releases/R2016b/stats/ttest.html?searchHighlight=ttest&s_tid=doc_srchtitle#btrj1_f-1
load examgrade
x = grades(:,1);
y = grades(:,2);
[h,p] = ttest(x,y)
the error I got :
Error using size
Dimension argument must be a positive integer scalar within indexing range.
Error in nanstd (line 59)
tile(dim) = size(x,dim);
Error in ttest (line 132)
sdpop = nanstd(x,[],dim);
The problem is probably at the call of nanstd which the dim=0.
The ttest function is read only from the statistics toolbox.
How to solve this problem?
1 commentaire
Wouter Maes
le 11 Oct 2017
Modifié(e) : Walter Roberson
le 11 Oct 2017
I have the exact same problem occurring. I tested several datasets, and ttest always gave this error.
(For instance, I did
Dist=makedist('Normal'); B1=random(Dist,1000,1); [h, p] = ttest(B1);
I always get the error:
Error using size
Dimension argument must be a positive integer scalar within indexing range.
Error in nanmean
Error in nanstd
Error in ttest (line 132)
sdpop = nanstd(x,[],dim);
I'm also runing Matlab R2016b. The statistics and machine learning toolbox is active and working.
Interestingly, I didn't have this error previously (the original script was written one month ago, and the ttest worked properly).
Réponses (1)
Walter Roberson
le 14 Sep 2017
1 vote
The code works fine for me when I test in R2016b.
When I look at the ttest code, the only way that dim could possibly be 0 is if five arguments had been passed into ttest and the 5th one was 0.
Meanwhile, the code for nanstd does not have 59 lines, and has no references to "tile" at all.
I suspect you are getting some different nanstd rather than toolbox/stats/stats/nanstd.m
1 commentaire
Steven Lord
le 11 Oct 2017
To test if Walter's suspicion is correct, use the which function to identify how many copies of the nanstd.m file you have on your path.
which -all nanstd
Catégories
En savoir plus sur Analysis of Variance and Covariance dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!