I understand that you are trying to plot a multiclass ROC curve in MATLAB using “fitcecoc” with SVM learners. From the code you shared, I noticed that you are manually calculating a variable named “diffscore” to pass into the “perfcurve” function. This is not needed and is the reason why your ROC curve appears incorrect (always reaching 1).
The “resubPredict” function with the “FitPosterior”, true option already provides posterior probabilities for each class, which can be directly used with “perfcurve”. To correctly generate ROC curves for a multiclass problem, you need to apply the “one-vs-all” strategy, i.e., compute and plot an ROC curve for each class individually.
Kindly refer to the below corrected code:
% Train multiclass SVM with posterior probabilities
template = templateSVM('Standardize',true,'KernelFunction','gaussian');
MultiClassSVM = fitcecoc(winedataset,'quality','Learners',template,'FitPosterior',true);
% Get posterior scores
[~,score_svm] = resubPredict(MultiClassSVM);
% Get class names
classNames = MultiClassSVM.ClassNames;
% Plot ROC for each class (one-vs-all)
figure;
hold on;
legendEntries = {};
for i = 1:numel(classNames)
    % Binary labels for current class vs rest
    trueClass = (winedataset.quality == classNames(i));
    % Use posterior scores for this class
    [X,Y,~,AUC] = perfcurve(trueClass, score_svm(:,i), true);
    % Plot ROC
    plot(X,Y,'LineWidth',1.5);
    legendEntries{end+1} = sprintf('Class %d (AUC = %.2f)', classNames(i), AUC);
end
xlabel('False Positive Rate');
ylabel('True Positive Rate');
title('Multiclass ROC Curve (One-vs-All)');
legend(legendEntries,'Location','Best');
grid on;
hold off;
With these corrections, now you will be able to visualize a separate ROC curve for each class “(3, 4, 5, 6, 7, 8)” and obtain the correct AUC values.
For further details, you may refer to the following MATLAB documentation on “perfcurve”:
I hope this is helpful!


