How to set ticks in imagesc colorbar based on a matrix value?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
Mathieu NOE
le 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')
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur White dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!