Here is the simplest answer that I could use, using a single while loop and assuming the cells Aboth Bcontain row vectors:
Level = zeros(size(A));
index = cellfun(@isequal, A, B);
while any(index)
Level(index) = max(Level)+1;
A = cellfun(@(c) {setdiff(c, unique([A{index}]))}, A);
index = cellfun(@isequal, A, B);
end
zeroes Level , A, . index, A B, cellfun isequal. , any index. Level Level . A concatenated unique, unique([A{index}]). ( cellfun), A, A . index , .
:
A = {[1 2 3]; [2 3]; 3; [1 2 3 4]};
B = {[1 2]; 2; 3; 4};
:
Level =
2
2
1
3