How to solve this error? Invalid types for comparison.

I want to calculate accuracy, sensitivity,...,etc based on actual and predicted data, this code is working well for numbered labels but it gives this error for string labels.

 Accepted Answer

@Bajdar Nouredine - for string labels, I suspect that you need to use strcmp rather than == for checking to see if two strings are identical (if that is what you mean). You would probably want to check the type (i.e. use isstring) first (of the ACTUAL and PREDICTED arrays) to determine whether you need to use strcmp or ==.

5 Comments

dear @Geoff Hayes thank you for response, honestly speaking, Iam not good to use such commands, I want to clarrify my purpose. I have 4 different datasets ('glioma'
'meningioma' 'notumor' 'pituitary' ) , actual.mat data is training data and predicted.mat is predicted, based on Evaluate.m I want to determone performance measurements like accuracy, Sensitivity, Specificty,..,etc
Can I solve this error inside Evaluate.m ? I appreciate your help
@Bajdar Nouredine the error message is
Error using == (line 30)
Invalid types for comparison.
Error in Evaluate (line 10)
idx = (ACTUAL()==1);
which is due to the above line. When ACTUAL is all strings, what are you attempting to compare with this line of code? What should it be?
yes ACTUAL and PREDICTED are all strings, I try to compare each name of actual.m with it is corresponding name in predicted.m in same colomn (compare actual (1) with predicted(2), actual(2) with predicted(2) and so on)
@Bajdar Nouredine - the ACTUAL and PREDICTED seem to be categorical arrays. I suppose you could convert to string arrays and then compare the two like
idx = strcmp(string(ACTUAL), string(PREDICTED)');
I had to transpose the PREDICTED array so that both it and ACTUAL are 288x1. idx should reference those elements/indices that match in both arrays.

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!