h = [1 1 0 1 0 1 0 1];bitrate = 1;n = 1000;T = length(h)/bitrate;N = n*length(h);dt = T/N;t = 0:dt:T;x = zeros(1,length(t));lastbit = 1;for i=1:length(h) if h(i)==1 x((i-1)*n+1:i*n) = -lastbit; lastbit = -lastbit; else x((i-1)*n+1:i*n) = lastbit; end end d=plot(t,x);grid on; title('Line code POLAR NRZ-I'); set(d,'LineWidth',2.5); axis([0 length(h) -1.5 1.5]); counter = 0; lastbit = 1;for i = 1:length(t) if t(i)>counter counter = counter + 1; if x(i)~=lastbit result(counter) = 1; lastbit = -lastbit; else result(counter) = 0; end end enddisp(result);
MATLAB: Can you make the output of this graph have multiple colors, like one timing bit is one color and the next one is another color.
color of plot linescolor varies within a single plot linevarying line color
Best Answer