MATLAB: How to find a number location in a multiple sub-matrices

arraycell arraysfindmatlab functionmatrix

I have a combined matric "z" which is included 3 sub-matrices "a", "b" and "c". RNG is a random number from matrix z. So, I want to know that this RNG is belongs to which sub-matrices?
a = [2;3;4;5];
b = [6;7;9;10;23];
c = [56;32];
z = [a;b;c];
rand = randperm(size(z,1));
RNG = z(rand(1),:);
RNG = % belong to which sub-matrices?

Best Answer

[tf, idx] = ismember(RNG, z);
[count, binnum] = histc(idx, cumsum([1, length(a), length(b), length(c)]);
varnames = {'a', 'b', 'c'};
fprintf('value %d came from matrix %s\n', RNG, varnames{binnum});