Here is a solution I saw in a master thesis on image retrieval (variable names changed):
R =f (:,:,1);% take all of the first element
G =f (:,:,2);
B =f (:,:,3);
R =R(1:end);%make it into one column matrix
G =G(1:end);
B =B(1:end);
%concentrate these R,G,B into a single 3 dimensional matrix
imf =[R;G;B];
imf =imf';
It looks like that the author made a detour. A simple solution to this problem is
imf= reshape(f, M*N, 3);
If the function 'reshape' is not used, their code can be improved as follows:
R =R(:);%make it into one vector matrix
G =G(:);
B =B(:);
%concentrate these R,G,B into a single 3 dimensional matrix
imf =[R,G,B];
Chinese version: