function [wR,muR,p_stdR]= order_mixture(w,mu,p_std,num_obs,num_comps)
% ORDER_MIXTURE sorts for w/p_std (in "descent" order) the Gaussian
% components;

% Test data:
% w=[10,11,12;22,20,21;32,31,30;22,20,21;]
% mu=w;
% pvar =[1,1,1;1,1,1;1,1,1;1,1,1];
% num_comps = 3;
% num_obs = 4;

[trash,a]   =   sort(w./p_std,2,'descend');
appoggio    =   repmat([1:num_obs],num_comps,1);
appoggio    =   appoggio(:);
a           =   a';
a           =   a(:);
right_order =   Couple2single(appoggio,a,num_obs,num_comps);
wR           =   reshape(w(right_order),num_comps,num_obs)';
p_stdR        =   reshape(p_std(right_order),num_comps,num_obs)';
muR          =   reshape(mu(right_order),num_comps,num_obs)';
return;
