Plotting a imagesc matrix with 5 different colors and categories.

Hi all,
I want to compare the two tables attached (their values excluded NaNs) producing a plot that resembles that of imagesc with more colors namely for true positives (1 in both tables), true negatives (0 in both tables), false positives (1 in table rec and 0 in table original), false negatives (0 in table rec and 1 in table original) and NaNs (left black or grey maybe).
How can I do so?
The result should be a matrix with the dimensions of the ones provided with elements colored according to the group they belong to (see the above).
Thank you,
Federico Nutarelli

 Accepted Answer

Hello Giorgio
I understand you want to compare two tables and generate new matrices based on following conditions.
true positives - 1 in both tables
true negatives - 0 in both tables
false positives - 1 in table rec and 0 in table original
false negatives - 0 in table rec and 1 in table original
NaN - if NAN or blank on both sides
Following is the code that can compare two tables to create resultant matrix
% Convert tables to matrices assuming they are already imported
recMatrix = table2array(rec_table_normalized);
originalMatrix = table2array(original_mat2014);
% Check if matrices have the same dimensions
if size(recMatrix) ~= size(originalMatrix)
error('Tables must have the same dimensions.');
end
% Create logical matrices for different groups
truePositives = recMatrix == 1 & originalMatrix == 1;
trueNegatives = recMatrix == 0 & originalMatrix == 0;
falsePositives = recMatrix == 1 & originalMatrix == 0;
falseNegatives = recMatrix == 0 & originalMatrix == 1;
nanVals = isnan(recMatrix) | isnan(originalMatrix);
% Create a matrix to represent the groups
colorMatrix = zeros(size(recMatrix));
colorMatrix(truePositives) = 1; % Set true positives to 1 (or any other value/color)
colorMatrix(trueNegatives) = 2; % Set true negatives to 2 (or any other value/color)
colorMatrix(falsePositives) = 3; % Set false positives to 3 (or any other value/color)
colorMatrix(falseNegatives) = 4; % Set false negatives to 4 (or any other value/color)
colorMatrix(nanVals) = 0;
disp(colorMatrix)
% imagesc(colorMatrix);
Thanks,
Karthik.

More Answers (0)

Products

Release

R2023a

Community Treasure Hunt

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

Start Hunting!