简体   繁体   中英

Matlab: save confusion matrix to file

I would like to save on file the confusion matrix that I get after the training phase.

[m,order]=confusionmat(YPred,YValidation)
m =
    18     8     3 
     3     5     1
     3     7    20
order = 
  7×1 categorical array
     classA
     classB
     classC

How can I save the confusion matrix with the labels associated with the columns and rows in a csv file?

Expected result

;ClassA;ClassB;ClassC
classA;18;8;0
classB;3;5;1     
classC;3;7;20     

You could assemble a cell array with your data and then export it:

q=cellstr(order);
writecell( [ {[]} q.'; q num2cell( m ) ], 'foo.txt', 'Delimiter', ';' );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM