Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Quick plotting question regarding MATLAB

Tags:

plot

matlab

I'm trying to plot a 5x5 matrix (call is a for now) composed of either +1 or -1. I want to plot this using a heat map such that a black square will represent a (-1) and a white square will represent a (+1). I think the appropriate command to should be image, however if I just do image(a) I don't get much...

Thanks in advance!

like image 328
Amit Avatar asked Sep 03 '26 01:09

Amit


2 Answers

You should instead use the function IMAGESC so it scales the display of the image values to the full range of the colormap. Then you can use the functions COLORMAP and GRAY to display the image as black (-1) and white (+1):

imagesc(a);
colormap(gray);
like image 52
gnovice Avatar answered Sep 05 '26 14:09

gnovice


Create a two-color colormap and offset the matrix values to fall within the colormap range:

>> image(a+1);
>> colormap([0 0 0; 1 1 1]);
like image 44
b3. Avatar answered Sep 05 '26 14:09

b3.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!