How to plot square diagram
이전 댓글 표시

Dear member, how to plot this figure in Matlab. Many thanks
Kind regards
채택된 답변
추가 답변 (2개)
Tran Hoa
2019년 10월 2일
0 개 추천
댓글 수: 6
Adam Danz
2019년 10월 2일
To change the xtick labels in the demo from my answer,
h = heatmap(data);
labels = sprintfc('%c','a':'t');
h.XData = labels; % <---change labels
Adam Danz
2019년 10월 2일
Tran Hoa's answer moved here as a comment. Please use the comment sections for discussion and the answer sescions for answer.
Why errors happen when I use this code as your instruction
data = diag(randi(20,1,20)+40);
heatmap(data)
xlabel('predicted')
ylabel('actual')
%Create colormap that looks like the image in the question
cm = [linspace(1,0,100)', linspace(1,0,100)', linspace(.875,1,100)']; %from [1 1 .875] to [0 0 1]
colormap(cm)
h = heatmap(data);
labels = sprintfc('%c','a':'t');
h.XData = labels; % <---change labels
Tran Hoa
2019년 10월 2일
Tran Hoa
2019년 10월 2일
Adam Danz
2019년 10월 2일
I see. sprintfc() is an undocumented built-in matlab function. Apparently you have another file with the same name and that file is a script.
That line is just creating fake labels, anyway. You probably already have your own labels. In any case, you can replace that line with this.
labels = strsplit(sprintf('%c ','a':'t'));
labels(end) = []
Tran Hoa
2019년 10월 2일
0 개 추천
댓글 수: 2
Tran Hoa
2019년 10월 3일
Adam Danz
2019년 10월 3일
@ Tran Hoa, this thread may become a bit difficult to follow when there are several "answers" posted that are not answer, but discussion. Please use the "comment" section under a particular answer or under the question if you'd like to continue discussion. The "answer" section is for proposing answer to the question stated at the top of the page.
You can't edit the text displayed in a heatmap. Here's a link to some alternatives:
카테고리
도움말 센터 및 File Exchange에서 Color and Styling에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




