I’m assuming that A
and B
are coordinates, and you want to “draw” the plot in matrix form, so try this:
c = flipud(full(sparse(B, A, B)));
I added flipud
to adjust the positive direction of the y-axis upwards.
Alternatively, you can obtain a binary matrix using this:
c1 = flipud(full(sparse(B, A, ones(size(A)))));
Important: for this solution to work, A
and B
must contain positive integer values. There is no sense in try to “plot” a matrix with non-positive or non-integer positions.
Example
A = 1:4; B = [3, 4, 3, 4];
c = flipud(full(sparse(B, A, B)))
c1 = flipud(full(sparse(B, A, ones(size(A)))))
This results in:
c =
0 4 0 4
3 0 3 0
0 0 0 0
0 0 0 0
c1 =
0 1 0 1
1 0 1 0
0 0 0 0
0 0 0 0
8
solved Create a larger matrix in special case [closed]