How can I do QPSK in MATLAB Could you please explain the step below, what is the benefit of it and how does it work. . 
I do qpsk demodulation, do I started doing the meshgrid,  

%%%%%%%de-qpsk    
 sM = 2;
 [x,y] = meshgrid((-sM+1):2:(sM-1),(-sM+1):2:(sM-1));
 alphabet = x(:) + 1i*y(:);  
 datadeqpsk=[];      

 for k=1:N                 
    datadeqpsk(k) = alphabet((dataqpdk_be(k) alphabet)==min(dataqpdk_be(k)-alphabet)); % dataqpdk_be is the data        
 end

datadeqpsk_R=real(datadeqpsk);
datadeqpsk_I=imag(datadeqpsk);
dataend=[];


Till now, all is ok, so what the benefit of below step? how does it work? could you please explain? 

     for ij=1:N
         dataend((ij-1)*2+1)=(datadeqpsk_R(ij)+1)/2;
         dataend(ij*2)=(datadeqpsk_I(ij)+1)/2;
    end
      R_D_data_out=[R_D_data_out dataend];


thank you very much
Your code is performing the QPSK demodulation. it's assigning the odd value for real value and even values for Imaginary valued Or, the opposite, try to re-check. And Then make the QPSK demodulation. 

About you question, how to do the qpsk demodulation,  you can do it as below: 

% suppose you have data for 48, 2-bit symbols
       data = randi([0 1],96,1);
 % Create a QPSK modulator System object with bits as inputs and Gray-coded signal constellation
       qpsk_mod = comm.QPSKModulator('BitInput',true);
 % Modulate and plot the data
       modData = step(qpsk_mod , data);
       scatterplot(modData)


Go to MATLAB and check the help of comm.QPSKModulator, then you can explore the demodulation easily. 

you can also check this web page for deep understanding https://www.gaussianwaves.com/2010/10/qpsk-modulation-and-demodulation-2/

Good Luck