MATLAB: Could anyone help me to solve the issue

remove

how to remove the partitions which contains {3},{4} and {3 4} in the following partitions of set{1 2 3 4} The 15 partitions of set {1 2 3 4}:
{1 2 3 4}
{1 2 3} {4}
{1 2 4} {3}
{1 2} {3 4}
{1 2} {3} {4}
{1 3 4} {2}
{1 3} {2 4}
{1 3} {2} {4}
{1 4} {2 3}
{1} {2 3 4}
{1} {2 3} {4}
{1 4} {2} {3}
{1} {2 4} {3}
{1} {2} {3 4}
{1} {2} {3} {4}

Best Answer

Using this FEX to illustrate, but you can similarly remove loop with your partition function.
A = SetPartition(4);
NotWanted = {[3] [4] [3 4]};
matchfun = @(s) any(cellfun(@(x) isequal(s,x), NotWanted));
b = cellfun(@(c) any(cellfun(matchfun,c)), A);
A(b) = [];
partdisp(A)
You'll get the following
The 5 partitions of set {1 2 3 4}:
{1 2 3 4}
{1 3 4} {2}
{1 3} {2 4}
{1 4} {2 3}
{1} {2 3 4}