The mask is the same for all thre channels, thus simply copy it.
I=... %image
M=... %mask
M3=cat(3,M,M,M);
F=zeros(size(I));
B=zeros(size(I));
F(M3)=I(M3);
B(~M3)=I(~M3);
Maybe foreground and background is switch, but I think you will get it.
A bit shorter, using multiplication instead of logical indexing:
I=... %image
M=... %mask
M3=cat(3,M,M,M);
F=M3.*I;
F=~M3.*I;