MATLAB Answers

Why do I get "Undefined function or variable" error?

2 ビュー (過去 30 日間)
Aaron Woods
Aaron Woods 2021 年 9 月 1 日
コメント済み: darova 2021 年 9 月 1 日
% Load in Data
yndata = load('exampledata1.txt');
g1 = yndata(:,1); % Known Group
g2 = yndata(:,2); % Predicted Group
C = confusionmat(g1,g2); % Return the confusion matrix.
% For Sensitivity
ND = sum(C(:,1)); % Number of disease cases
DD = C(1,1); % Number of cases clasified as positive that are true
% For Specificity
NP = sum(C(:,2)); % Number of healthy cases
PP = C(2,1); % Number of cases classifed as negative that are true
ROCpoint(yndata)
function [Sensitivity, Specificity] = ROCpoint(yndata)
% Gets Sensitivity
Sensitivity = DD / ND;
Specificity = PP / NP; % Gets Specificity
end
My error message is
Unrecognized function or variable 'DD'.
Error in HW2>ROCpoint (line 23)
Sensitivity = DD / ND;
Error in HW2 (line 19)
ROCpoint(yndata)

採用された回答

darova
darova 2021 年 9 月 1 日
I think your main code should be inside function body

その他の回答 (1 件)

Image Analyst
Image Analyst 2021 年 9 月 1 日
You need to pass them in
ROCpoint(DD, ND, PP, NP) % Call, passing in variables.
% Declare function with all needed variables.
function [Sensitivity, Specificity] = ROCpoint(DD, ND, PP, NP)
  1 件のコメント
darova
darova 2021 年 9 月 1 日
i disagree

サインインしてコメントする。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by