You can create this kind of plot quite easily using the built-in functions imagesc and text and setting a number of parameters for graphic objects. Here is an example:
mat = rand(5); % A 5-by-5 matrix of random values from 0 to 1 imagesc(mat); % Create a colored plot of the matrix values colormap(flipud(gray)); % Change the colormap to gray (so higher values are % black and lower values are white) textStrings = num2str(mat(:), '%0.2f'); % Create strings from the matrix values textStrings = strtrim(cellstr(textStrings)); % Remove any space padding [x, y] = meshgrid(1:5); % Create x and y coordinates for the strings hStrings = text(x(:), y(:), textStrings(:), ... % Plot the strings 'HorizontalAlignment', 'center'); midValue = mean(get(gca, 'CLim')); % Get the middle value of the color range textColors = repmat(mat(:) > midValue, 1, 3); % Choose white or black for the % text color of the strings so % they can be easily seen over % the background color set(hStrings, {'Color'}, num2cell(textColors, 2)); % Change the text colors set(gca, 'XTick', 1:5, ... % Change the axes tick marks 'XTickLabel', {'A', 'B', 'C', 'D', 'E'}, ... % and tick labels 'YTick', 1:5, ... 'YTickLabel', {'A', 'B', 'C', 'D', 'E'}, ... 'TickLength', [0 0]);
And this figure generates:

If you encounter problems with the x-axis tick ticks, you select too wide and overlap each other, here's how you can handle this:
Newer versions of MATLAB: You do not know which version was added, but in newer versions, axes now have properties '{X|Y|Z}TickLabelRotation' , which allow you to rotate labels and fit better into them.
Old versions of MATLAB:. For older versions, you can find some materials in the MathWorks File Exchange , which can rotate label text labels, for example XTICKLABEL_ROTATE from Brian Katz .
gnovice Oct. 15 2018-10-15 15:57
source share