creating partition of sets

4 views (last 30 days)
k khaja on 16 Feb 2021
Edited: k khaja on 18 Feb 2021
I am getting error, can anyone correct it please. Thanks in advance.
%A partition of a set A is a finite or infinite collection of nonempty, mutually disjoint subsets whose union is A.
A = [0, 1, 2, 3, 4]
C = {}; D = [];
j = 1;
while j < 10
P = input('Enter INTEGERS with [ ] around them');
D = cell2mat(C)
if ismember(P,A) == ones(1,length(P)) && ismember(P,D) ~= ones(1,length(D))
C{(end+1)} = P;
else
disp('Entered wrong, Please Enter correct one\n');
j = j;
end
j = j + 1;
end

Walter Roberson on 16 Feb 2021
if ismember(P,A) == ones(1,length(P)) && ismember(P,D) ~= ones(1,length(D))
P is a vector. ismember() is going to return a vector the same length. == comparison to ones is going to return a vector the same length. You cannot use && with vectors
You could perhaps replace the first test with
if all(ismember(P, A))
Your second test is harder to make sense of as your documentation does not make clear what you want to have happen if some entries match but others do not. I seem to be having difficulty translating your documentation as to what the program is intended to do or how it is intended to do it.
My guess:
if all(ismember(P, A)) && ~any(ismember(P, D))
k khaja on 18 Feb 2021
Edited: k khaja on 18 Feb 2021
To create a partition, first I have to check the main set A, whether all are from this set and second test will check whether the same elements already choosen for any other other partion C, and I converted C to single matrix D for comparison purpose.
Thanks a lot Walter, your guess is right and It worked, this is what I want.

Categories

Find more on Resizing and Reshaping Matrices in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by