# creating partition of sets

5 visualizaciones (últimos 30 días)
k khaja el 16 de Feb. de 2021
Editada: k khaja el 18 de Feb. de 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
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

### Respuestas (1)

Walter Roberson el 16 de Feb. de 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))
##### 1 comentarioMostrar -1 comentarios más antiguosOcultar -1 comentarios más antiguos
k khaja el 18 de Feb. de 2021
Editada: k khaja el 18 de Feb. de 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.

Iniciar sesión para comentar.

### Categorías

Más información sobre Logical en Help Center y File Exchange.

### Community Treasure Hunt

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

Start Hunting!

Translated by