How to set ticks in imagesc colorbar based on a matrix value?
1 次查看(过去 30 天)
显示 更早的评论
I'm using imagesc to display a graph/image, and I'm having trouble with the piece of code dislpayed here - specifically the ticks in colorbar.
imagesc(x,y,A);
title(['Graph']);
colorbar('Ticks',[0, 0.25, 0.5, 0.75, 1], 'TickLabels',{'Safe','Low', 'Medium','Medium-High', 'High'})
xlabel('X')
ylabel('Y')
A is a 17x22 matrix (x is 1x22 and y is 1x17). Above code works when the values of A are between 0 and 1, as intended.
How can I identify the maximum and minimum value within A and divide the difference accordingly (by 5, in this case) to set the Ticks in colorbar?
0 个评论
采纳的回答
Mathieu NOE
2021-1-4
hello
this is how you can make the ticks range match the A range
demo :
A = 15*rand(17,22);
imagesc(A);
title(['Graph']);
colorbar('Ticks',linspace(min(A,[],'all'),max(A,[],'all'),5), 'TickLabels',{'Safe','Low', 'Medium','Medium-High', 'High'})
xlabel('X')
ylabel('Y')
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 White 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!