ttest Matlab R2016b does not work properly
显示 更早的评论
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 个评论
Wouter Maes
2017-10-11
编辑:Walter Roberson
2017-10-11
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).
回答(1 个)
Walter Roberson
2017-9-14
1 个投票
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 个评论
Steven Lord
2017-10-11
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
类别
在 帮助中心 和 File Exchange 中查找有关 Analysis of Variance and Covariance 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!