matlab - plot elements of array with different colors -
i have vector of integers vary 1 4.
a=[1 2 3 4 2 3 2 1 2 3 4 4]
i plot different colors each value... vertical line links a(1) a(2) should have color of first value (in case 1).
is possible?
and how handle case of nan nowadays in vector? should plot against time vector
a = [1 1 1 nan 4 4 4 nan 2 2 3 3]; time = [1 2 3 4 5 6 7 8 9 10 11 12];
suppose have next set of colors:
col = hsv(4);
you set order of colors based on values of a:
figure(); set(gca, 'colororder', col(a,:), 'nextplot', 'replacechildren');
then, can plot each line in desired color:
n = numel(a); plot(hankel(0:1,1:n-1),hankel(a(1:2),a(2:n)))
this results in:
edit: hankel
approach bit shooting bazooka kill mosquito, in netherlands. anyway, learned few questions ago - liked utilize it. see post of dan simpler alternative plotting. still, setting right colors can done in above.
matlab colors plot
No comments:
Post a Comment