How to plot binary matrix as dots?
40 ビュー (過去 30 日間)
古いコメントを表示
I have a Matrix with ones and zeroes. How to plots the matrix with zeroes as black spot and ones as whote dots as shown in figure below.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/739834/image.png)
0 件のコメント
採用された回答
Star Strider
2021 年 9 月 15 日
Try this —
M = randi([0 1],25)>0; % Logical Matrix
[r,c] = find(M);
figure
scatter(c, r, 75, 'sw', 'filled')
set(gca, 'Color','k', 'YDir','reverse')
axis([0 size(M,1)+1 0 size(M,2)+1])
% axis('equal')
The spy function works for this, however it does not have the ability to fill the markers, so I went with scatter instead.
figure
spy(M,'sw');
set(gca, 'Color','k')
hs.MarkerFaceColor = 'w';
Experiment to get the result you want.
.
0 件のコメント
その他の回答 (3 件)
millercommamatt
2021 年 9 月 15 日
FH = figure;
imagesc(yourMatrix);
colormap(FH,[0,0,0;1,1,1]);
0 件のコメント
the cyclist
2021 年 9 月 15 日
M = magic(7);
B = M > mean(M);
colormap('gray')
imagesc(B)
axis square
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!