MATLAB: Excluding some elements from a Vector elementvectors qw=[1:0.4:50]';c=[9,17,25, 31,43]' I wish to exclude all the elements that are c-0.5 to c+0.5 Best Answer qw = 1:0.4:50;c = [9;17;25;1;43];tol = .5;(a) Bsxfun solutionOut = qw(~any(bsxfun(@ge, qw, c-tol) & bsxfun(@le, qw, c+tol)));(B) Arrayfun solutionOut = qw(~arrayfun(@(x) any(x >= c-tol & x <= c+tol),qw)) Related SolutionsMATLAB: Replication factors must be a row vector of integers or integer scalars. c must be an integer. Then, a solution:depth = [0.01 1.5:1.5:30]';w = 10 - 0.5 .* depth;w(w<0) = 0;a=829862;b=21c=round(a/b)W = repmat(w,c,1); MATLAB: How to set the maximum iteration while looping Before the loop:iter = 0;Then change the while towhile iter <= 5 && tol > 0 iter = iter + 1; Related QuestionWeighted linear combination between vectorsHow to create a random matrix that contains only of 0’s, 0.5’s and 1’sHow to create a matrix where every combination of numbers between 0 and 1 (step x) is used and every row sums to oneAll possible n-length combinations of two numbersHow to used the combination between “bsxfun” and “operator AND”
Best Answer