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

5 Ansichten (letzte 30 Tage)
Jake
Jake am 4 Jan. 2021
Kommentiert: Jake am 4 Jan. 2021
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?

Akzeptierte Antwort

Mathieu NOE
Mathieu NOE am 4 Jan. 2021
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')

Weitere Antworten (0)

Kategorien

Mehr zu Colormaps finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by