function  [string,ls_index,p,plt_index]=plot_fig(a,b,kp,ki,kd,target,string,max_time,val,str,val2)
     
    if(ishandle(1) == 0) %Check if any figure is open.
        temp=string{val}; %If not use the 
        figure(1);
        set(gcf,'Position',get(0,'Screensize'));
        subplot(1,2,1);
        axis([0 max_time 0 400]);
        hline = refline([0 target]);
        set(hline,'Color','r');
        string={};
        ls_index=1;
        string{ls_index}=str;
        ls_index=ls_index+1;
        string{ls_index}=temp;
        ls_index=ls_index+1;
       
    else
        ls_index=val+1;
    end
        figure(1);
        subplot(1,2,1);
        stri='DC Position Control PID Response Comparision';
        title(stri);
        xlabel('Time in seconds');
        ylabel('Angle in Degrees');
        axis([0 max_time 0 400]);
        hold on;
        b=[0 b];
        a=[a(1) a];
        p(val2)=plot(b,smooth(a),'color',rand(1,3));
        plt_index=val2+1;
        legend(string{:});
        grid on;
        grid minor;
        hold on;
        

        
end
