MATLAB: Error using < Matrix dimensions must agree. conditionnan a=randi(100,1,10); b=randi(100,1,10); c=randi(100,1,10); A=[a;b;c] A_max=max(A); A(A<0.15*A_max)=nan it gives following error Error using < Matrix dimensions must agree. How to rectify it… Best Answer You apparently have R2016a or earlier, so you do not have ‘automatic implicit expansion’ that was part of R2016b and later versions. Try this: idx = bsxfun(@lt, A, 0.15*A_max);A(idx) = NaN;You can combine them in one line if you like. This code illustrates the approach. Related SolutionsMATLAB: Finding the maximum value table A for values in table B bellow benchmark One possible way, assuming that values in A are always positive:AA = repmat(A', 1, numel(C));D = max(AA .* bsxfun(@le, B', C))If you want it to work even with negative values in A, it's only slightly more complicatedAA = repmat(A', 1, numel(C));D = max(AA .* (0./bsxfun(@le, B', C) + 1)) %0./x+1 change a logical matrix of [0, 1] into a matrix of [Nan, 1] MATLAB: BUG in nargin < 3 The example works as expected for me. It throws an error because no value is assigned to y>> y = myfunction( 1, 2, true )Output argument "y" (and maybe others) not assigned during call to "myfunction". There is no else clause of the outer if-statement. /R2018b Related QuestionMultiply mx1 matrix to mxn matrixPlease help me with coding up “-5 < x < 3"Error of matrix dimensions must agreeA < b < c < d, what does this Boolean return for different values of a, b, c and dMatrix dimensions must be agreeError when I concatenated matricesSmallest n such that vector(n) < a
Best Answer