How to set ticks in imagesc colorbar based on a matrix value?

7 ビュー (過去 30 日間)
Jake
Jake 2021 年 1 月 4 日
コメント済み: Jake 2021 年 1 月 4 日
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?

採用された回答

Mathieu NOE
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 ExchangeColormaps についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by