Matlab:内置和外部功能的混合

时间:2015-12-21 16:32:58

标签: matlab

Matlab(2015a)表现得很奇怪:许多内置函数没有按预期响应。例如,输入

SodiumSpecimeninsufficientfortest(s)PotassiumSpecimeninsufficientfortest(s)ChlorideSpecimeninsufficientfortest(s)BicarbonateSpecimeninsufficientfortest(s)UreaSpecimeninsufficientfortest(s)AuthorisedbyIMMofokengon04/07/2015at17:02Creatinine116Humol/L64-104eGFR(MDRDformula)>60mL/min/1.73m2MDRD-derivedestimationofGFRmaysignificantlyunderestimatetrueGFRinpatientswithGFR>60mL/min/1.73m^2.Itmayalsobeunreliableinthecaseof:age<18yearsor>70years;pregnancy;seriousco-morbidconditions;acuterenalfailure;extremesofbodyhabitus/unusualdiet,grossoedema.TheMDRD-eGFRusedheredoesnotemployanethnicfactorforrace.AuthorisedbyIMMofokengon04/07/2015at17:02Calcium2.44mmol/L2.15-2.55AuthorisedbyIMMofokengon04/07/2015at17:02Magnesium0.88mmol/L0.63-1.05AuthorisedbyIMMofokengon04/07/2015at17:02Inorganicphosphate1.47Hmmol/L0.78-1.42AuthorisedbyIMMofokengon04/07/2015at17:02Totalprotein77g/L60-78AuthorisedbyIMMofokengon04/07/2015at17:02Albumin48g/L35-52AuthorisedbyIMMofokengon04/07/2015at17:02Totalbilirubin8umol/L5-21AuthorisedbyIMMofokengon04/07/2015at17:02Conjugatedbilirubin(DBil)1umol/L0-3Alaninetransaminase(ALT)Specimeninsufficientfortest(s)AuthorisedbyIMMofokengon04/07/2015at17:02Aspartatetransaminase(AST)26U/L15-40AuthorisedbyIMMofokengon04/07/2015at17:02Alkalinephosphatase(ALP)61U/L53-128AuthorisedbyIMMofokengon04/07/2015at17:02Gamma-glutamyltransferase(GGT)18U/L<68Thyroidstimulatinghormone(TSH)Specimeninsufficientfortest(s)Thyroxine(freeT4)Specimeninsufficientfortest(s)AuthorisedbyMJModungoaon02/07/2015at08:23WhiteCellCount9.75x109/L3.92-10.40RedCellCount5.29x1012/L4.19-5.85Haemoglobin15.9g/dL13.4-17.5Haematocrit0.474L/L0.390-0.510MCV89.6fL83.1-101.6MCH30.0pg27.8-34.8MCHC33.5g/dL33.0-35.0RDW13.6%12.1-16.3PlateletCount217x109/L171-388MPV10.0fL7.1-11.0Neutrophils65.60%6.40x109/L1.60-6.9832.00-76.00Lymphocytes25.90%2.53x109/L1.40-4.2018.00-56.00Monocytes5.60%0.55x109/L0.30-0.804.00-12.00Eosinophils0.50%0.05x109/L0.00-0.950.00-8.00Basophils0.20%0.02x109/L0.00-0.100.00-2.00"Other"Cells2.10%0.20x109/LMarkallunreadasreadMarkallunviewedasviewedPrintReport

结果

ttest([1 2], [1 2])

如果我为每个功能执行以下操作:

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);

我得到了,得到了解答:

which size
which nanstd
which ttest

这些文件中的每一个看起来都很好,只是size.m的每一行都被注释掉了。

这可能是什么问题?

1 个答案:

答案 0 :(得分:2)

也许与您的问题有关:

R2013a的

ttest进行以下调用:

sdpop = nanstd(x,[],dim);

R2013a版本nanstd的帮助文件声明:

Y = nanstd(X,FLAG,DIM) takes the standard deviation along dimension DIM of X.

另一方面,2005 nanstddownloaded off Mathworks file exchange中的nansuite指出:

  FORMAT: Y = nanstd(X,DIM,FLAG)

注意DIM和FLAG是如何反转的!

如果我调用R2013a的ttest这样它会调用旧的2005 nansuite函数nanstd,那么Matlab会生成类似于你的错误:

Error using size
Dimension argument must be a positive integer scalar within indexing range.

Error in nanmean (line 46)
count = size(x,dim) - sum(nans,dim);

Error in nanstd (line 54)
avg = nanmean(x,dim);

Error in ttest (line 132)
sdpop = nanstd(x,[],dim);

如果将[]作为DIM而不是FLAG传递,则nanstd对size(x, DIM)的调用会触发错误,因为[]不是正整数标量。如果这样的事情是原因,那么更广泛的问题是,您的Matlab安装或设置或下载会发生什么,或者您正在调用古代代码?或者为什么那个古老的代码甚至到处都是?我不知道在Matlab的发布历史中,nanstd(x, FLAG, DIM)在什么时候被支持(而不仅仅是nanstd(x, DIM))?

档案:以下是我错误诊断您的问题的旧答案

您的两个示例向量xy都相同(即[1,2])。差异的估计差异为0,您的所有统计信息都将以NaN爆炸。

逐步完成统计数据,并清楚发生了什么。

x = [1; 2];  % Data you used in the example.
y = [1; 2];  % Data you used in the example.
z = x - y;   % Your call to ttest tests whether this vector is different from zero at a statistically significant level.

现在我们在z

上完成所有统计数据
r.n  = length(z);
r.mu = mean(z);
r.standard_error = sqrt(var(z,1) / (r.n-1));    % For your data, this will be zero since z is constant!
r.t = r.mu ./ r.standard_error;              % For your data, this will be inf because dividing by zero!
r.df = r.n - 1;
r.pvals(r.t >= 0) = 2 * (1 - tcdf(r.t(r.t>=0), r.df));  % For your data, tcdf returns NaN and this all fails...
r.pvals(r.t < 0)  = 2 * tcdf(r.t(r.t<0), r.df);

等...

这应该与来电相匹配     [h, p, ci, stats] = ttest(x-y);