function x=PtoX(P,q,c)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%       
% 
% Folding a state vector from the Riccati matrices
% 
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%

n=length(q);

k=0;

for i=1:n
   for j=1:i
       k=k+1;
       x(k,1)=P(i,j);  % P beeing symmetric
   end
end

for i=1:n
    k=k+1;
    x(k,1)=q(i,1);
end

x(k+1,1)=c;

%%%%%%%%%%%%%% end of file %%%%%