不返回if语句中的值,MATLAB

时间:2014-10-18 20:29:57

标签: matlab if-statement

我正在评估数据集的准确性置信区间,并且我计算95%或99%的置信区间,但是对应于较低区间和较高区间的值未从函数返回,请指导我我到底做错了什么:

function [Accuracy,lowerInterval,upperInterval] = ConstructInterval(Ypredict, Ytest, confLevel)
n = size(Ypredict,1);
correct = Ypredict == Ytest;
Accuracy = mean(correct);
confLevel = floor(confLevel*100);
if(confLevel == 99)
    lowerInterval = Accuracy - 2.576*sqrt(Accuracy*(1-Accuracy)/n);
    upperInterval = Accuracy + 2.576*sqrt(Accuracy*(1-Accuracy)/n);
end
if(confLevel == 95)
    lowerInterval = Accuracy - 1.96*sqrt(Accuracy*(1-Accuracy)/n);
    upperInterval = Accuracy + 1.96*sqrt(Accuracy*(1-Accuracy)/n);
end
Accuracy = 100*Accuracy;
lowerInterval = lowerInterval*100;
upperInterval = upperInterval*100;
end

谢谢。

1 个答案:

答案 0 :(得分:0)

问题在于,当我调用函数时,我只将值保存为:

f = ConstructInterval(y(testInstanceLabel == 1),pred_linear, 0.99)

而不是

[f,g,h] = ConstructInterval(y(testInstanceLabel == 1),pred_linear, 0.99)

新秀错误。