%
%plots evolution of C2/C1 maps for two states q0,q1 and two TNs p1,2,3
%
%urut/sept08
%urut/dec10: customized version for rivalry simulations (has only p1/p2)
%
function ax = plotDoubleWTARun_rivalry(C2,C1,q0,q1,p1,p2, inpHistory, inpHistorySymb, tillPlot)
sc = 1000;

widthLine   = 2;
sizeFont    = 12;
sizeMarker  = 10;

header

inds2=1:tillPlot;


ax(1)=subplot(2,3,1);
inds=[1:tillPlot]/sc;
plot( inds, C2(q0,inds2), 'b', inds, C2(q1,inds2), 'r', inds, C2(end,inds2), 'g')
legend('q1','q2','Inhib');
title('map C2 (state)');
%ylim([0 17]);
xlabel('t (integration steps/1000)');

ax(2)=subplot(2,3,2);

indsBoth = find( C1(p1,inds2)>0 & C1(p2,inds2)>0 );
plot( inds, C1(p1,inds2), 'b', inds, C1(p2,inds2), 'r',  inds, C1(end,inds2), 'c', inds, inpHistorySymb(p1,inds2), 'b--', inds, inpHistorySymb(p2,inds2), 'r--');

%debugging - to plot situations hwere both p1&p2 are active
%hold on
%plot( inds(indsBoth), 8, 'm');
%hold off

legend('i1','i2 ','Inhib', 'ext inp i1','ext inp i2');
title('map C1 (TNs)');

ax(3)=subplot(2,3,3);

plot( inds(1:end-1), diff(C2(q0,inds2)),'Color','b');
hold on
plot( inds(1:end-1), diff(C2(q1,inds2)), 'Color', 'r');
plot( inds(1:end-1), diff(C2(end,inds2)), 'Color', 'c');
ylabel('derivative state units in C2');


ax(4)=subplot(2,3,4);
plot( inds(1:end-1), diff(C1(p1,inds2)), 'g', inds(1:end-1), diff(C1(p2,inds2)), 'r', inds(1:end-1), diff(C1(end,inds2)), 'c');
ylabel('derivative units in C1');
legend('d(i1)','d(i2)','d(Inhib)');

linkaxes(ax,'x');
xlabel('t (integration steps)');
set(ax(1),'xlim',[20000 50000]/sc);
