Yesterday is history, tomorrow is a mystery, but today is gift. That's why we called it the present. >>>>>>> 点此联系我

Matlab table类型变量使用示例

clear;

CM = load('confusionMatrix_5Exp.mat');

fieldNames = fieldnames(CM);
fieldNames = fieldNames';
varNames = {'CM', 'Sen', 'Spc', 'Prc', 'F1', 'Acc'};
varTypes = {'cell', 'double', 'double', 'double', 'double', 'double'};

CMCell = cell(numel(fieldNames),1);
CMTable = table('Size', [numel(fieldNames) numel(varNames)], 'VariableTypes', varTypes, 'VariableNames', varNames, 'RowNames', fieldNames);
for iField = 1:numel(fieldNames)
    curCM = getfield(CM, fieldNames{iField});
    resultCM = genRes(curCM);
    CMCell{iField} = curCM;
    CMTable(iField, :) = {{curCM}, resultCM.Sensitivity, resultCM.Specificity, resultCM.Precision, resultCM.F1, resultCM.Accuracy};
    
end

%% Support Functions
function resultCM = genRes(CM)
resultCM.Sensitivity = CM(1,1)/(CM(1,1) + CM(2,1));
resultCM.Specificity = CM(2,2)/(CM(2,2) + CM(1,2));
resultCM.Precision = CM(1,1)/(CM(1,1) + CM(1,2));
resultCM.F1 = 2*((resultCM.Precision*resultCM.Specificity)/(resultCM.Precision+resultCM.Specificity));
resultCM.Accuracy = (CM(1,1)+CM(2,2))/sum(CM, 'all')*100;

end

% 附件地址:https://files.cnblogs.com/files/virter/confusionMatrix_5Exp.rar
posted @ 2020-09-08 21:52  virter  阅读(2429)  评论(0编辑  收藏  举报