MATLAB: Check if elements in an array are equal to 0 1 or 2 arrays i have been given a random sqaure matrix. how do i check that all the elements witihin my array are equal to 0,1 or 2? Best Answer "how do i check that all the elements witihin my array are equal to 0,1 or 2? ">> A = randi([0,2],4) % should passA = 1 0 0 2 1 2 0 2 2 0 2 2 1 1 1 1>> all(ismember(A(:),0:2))ans = 1>> A = randi([0,9],4) % should failA = 8 0 3 0 6 6 3 6 6 0 5 1 4 2 1 1>> all(ismember(A(:),0:2))ans = 0 Related SolutionsMATLAB: How to create permutations of multisets Try thisx = [0 0 1 1 2 2];M = unique(perms(x), 'rows'); MATLAB: Counter odd numbers in ‘randi’ Try this:a=randi([0 27],1,50)numberOfOddNumbers = sum(rem(a, 2)) Related QuestionHow the computation happening : sum(A~=0,2)Area from XY coordniatesHow to generate random numbers in a range with decimal stepsSteps between to elements of a matrixComparing Contents of Two MatricesA and B are coupled vectors. How to get from A->A_new B-> B_new
Best Answer