How can I display a 2D binary matrix as a black & white plot?

前端 未结 3 764
半阙折子戏
半阙折子戏 2020-12-16 15:22

I have a 2D binary matrix that I want to display as a black and white plot. For example, let\'s say I have a 4-by-4 matrix as follows:

1 1 0 1
0 0 1 0
1 1 0          


        
3条回答
  •  鱼传尺愫
    2020-12-16 16:01

    I'm not sure if I got your question right, but you may try the image function, like this:

    A = [ 1 1 0; 1 0 1; 1 1 1 ];
    colormap([0 0 0; 1 1 1 ]);
    image(A .* 255);
    

提交回复
热议问题