Nate
Nate

Reputation: 101

How to generate a image that contains a matrix like this in MATLAB?

enter image description here

Suppose we have a 0-1 matrix, I want to generate a picture that is white in 0 entry and black in 1 entry, like the picture above.

Upvotes: 0

Views: 76

Answers (1)

Matteo V
Matteo V

Reputation: 1163

You can use imagesc(), with a gray colormap:

n = 10; % size of your matrix
a = randi(2, n, n) - 1; % random matrix containing only 1s and 0s

imagesc(a)
colormap gray

Upvotes: 2

Related Questions