Enzo Bruckmamaan
Enzo Bruckmamaan

Reputation: 37

How to display values in matrix as colors?

I've got a matrix A in MATLAB with the two values '100' and 'NaN' (the matrix below is just a simplified version of the original one). How can I display the values as black and white: for example '100' should appear as a black square and 'NaN' as a white square

A = [NaN NaN NaN 100 100; NaN NaN NaN 100 NaN; 100 NaN 100 NaN NaN];

Upvotes: 0

Views: 53

Answers (1)

Suever
Suever

Reputation: 65430

You can just display the result of isnan. This will yield a true (white) value for all NaN's and false (black) for all non-NaN's.

imshow(isnan(A));

If you don't have the Image Processing Toolbox you can use imagesc instead

imagesc(isnan(A));
colormap gray
axis image

Upvotes: 2

Related Questions