Assuming img
is a MxNx3 image, you can do it like this:
[M, N, ~] = size(img);
plot3(...
reshape(img(:,:,1), 1, M * N), ...
reshape(img(:,:,2), 1, M * N), ...
reshape(img(:,:,3), 1, M * N), '.')
xlabel('Red'), ylabel('Green'), zlabel('Blue')
grid on