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!