Visualizing values in a matrix

3 vues (au cours des 30 derniers jours)
antifreund
antifreund le 8 Juil 2020
Modifié(e) : KSSV le 8 Juil 2020
Hi there,
I wrote a script that runs loops on a 100x100 matrix and changes values within. That matrix only contains ZEROS and ONES and I would like to visualize the development of the ONES for each iteration.
From what I gathered, I 'pcolor' is the way to go but I am not at all sure how to implement that.
Lets say it is only a 10x10 matrix, like so:
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 1 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 1 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 1 0 0
0 0 0 0 0 0 0 0 0 0
I would like to turn this into something like this:
The numbers for row and column are not needed and neither is the outer border...
I am sure it turns out to be a simple one-liner ... So, if anyone of you know how, please help.
Your help is much appreciated!!!

Réponse acceptée

KSSV
KSSV le 8 Juil 2020
Modifié(e) : KSSV le 8 Juil 2020
Read about spy
clc; clear all ;
m = 10 ;
A = zeros(m);
% introduce random ones
id = randperm(m*m,20) ;
A(id) = 1 ;
[m,n] = size(A) ;
[Y,X] = meshgrid(1:m,1:n) ;
idx = find(A) ;
plot(X(idx),Y(idx),'s','edgecolor','r')
You can use scatter to plot squares with colors.
  1 commentaire
antifreund
antifreund le 8 Juil 2020
This is just perfect!!!! Thanks a million!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Discrete Data Plots dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by