matlab - Create a larger matrix in special case -
i have 2 vectors:
a=[1 2 3 4] b=[3 5 3 5]
i want find matrix these vectors this:
you can suppose c
plot matrix
, x-axis a
, y-axis
b
:
c = 0 4 0 4 3 0 3 0 0 0 0 0 0 0 0 0
or:
c1= 0 1 0 1 1 0 1 0 0 0 0 0 0 0 0 0
my question how create automatically because have large vectors.
i'm assuming a
, b
coordinates, , want "draw" plot in matrix form, try this:
c = flipud(full(sparse(b, a, b)));
i added flipud
adjust positive direction of y-axis upwards.
alternatively, can obtain binary matrix using this:
c1 = flipud(full(sparse(b, a, ones(size(a)))));
important: solution work, a
, b
must contain positive integer values. there no sense in try "plot" matrix 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
Comments
Post a Comment