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

4 visualizaciones (últimos 30 días)
Jake
Jake el 4 de En. de 2021
Comentada: Jake el 4 de En. de 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?

Respuesta aceptada

Mathieu NOE
Mathieu NOE el 4 de En. de 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')

Más respuestas (0)

Categorías

Más información sobre Colormaps en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by