Hi Melih,
As per my understanding, you want to make a heatmap which should be like the picture attached with the query. The heatmap should have colour based on the input, should have text inside and black boundaries between cells.
‘imagesc’ and ‘text’ function can be used to achieve this. ‘line’ function can be used to add boundaries on the heatmap.
- Assuming the values to create the heatmap are in ‘heatMapValues’ variable then using ‘imagesc’ heatmap can be created. Refer to the following code snippet.
heatMapValues = rand(4, 4);
2. Text can be written inside cell using ‘text’ function and ‘sprintf’ can be used to format the data. The following code snippet can be used to write character ‘x’ in the cell with number ‘4’ as superscript.
[nRows, nCols] = size(heatMapValues);
text(col, row, sprintf('%s^{%d}', 'x', 4), ...
'HorizontalAlignment', 'center', ...
3. To add black boundaries to the cells, ‘line’ function can be used. Lines can be drawn on the existing plot, ‘LineWidth’ can be changed to get the boundary of desired thickness. Refer to the following code snippet:
line([0.5, nCols+0.5], [row, row], 'Color', 'k', 'LineWidth', 10);
line([col, col], [0.5, nRows+0.5], 'Color', 'k', 'LineWidth', 10);
Please refer to the documentation of ‘imagesc’, ‘text’, ‘sprintf’ and ‘line’ for more information:
- “limagesc”: www.mathworks.com/help/matlab/ref/imagesc.html
- “text”: www.mathworks.com/help/matlab/ref/text.html
- “sprintf”: www.mathworks.com/help/matlab/ref/sprintf.html
- “line”: www.mathworks.com/help/matlab/ref/line.html
Hope this helps!