creating partition of sets
조회 수: 5 (최근 30일)
이전 댓글 표시
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
답변 (1개)
Walter Roberson
2021년 2월 16일
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))
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!