Find and replace array elements that meet a... Learn more about find array elements that meet a condition, replace values that meet a conditionWhile it may be possible to do it without a loop, with a combination of diff, find and possibly cumsum it's going to be a lot more obscure than a simple loop and probably not any more efficient. The simplest loop would be: for idx = find (A == 4) A (idx) = A (idx-1); end. which also works for consecutive elements to replace.
The complete array displays corrolations between Polynomials, e.g: 1 (Col1 Index 1) and 3 (Col2 Index 1) corrolate with a value of -0.5 (v Index 1). Since the Integers 1 to 36 identify the "Type" of a Zernike Polynomial, i want to replace them with the actual name of the Polynomial.
Sep 21, 2018 · Edited: Stephen on 21 Sep 2018. You cannot replace part of an array with another array that has a different number of elements (unless the replacement is a scalar). But you can easily use indexing to get the parts of the array that you want to keep, and concatenate them together to create a new array: q = 1/16; S = 0.25; Nov 04, 2017 · A = randn (5)+2; % Random example [row,col] = find (A<1); A (:,col) = NaN; If you would want to keep the values smaller than 1 in the matrix a solution could look something like this: A = randn (5)+2; % Random example [row,col,ind] = find (A<1); b = A (ind) A (:,col) = NaN; A (ind) = b; Share. Improve this answer. The strrep function does not find empty character vectors or empty strings for replacement. That is, when str and old both contain the empty character vector ('') or the empty string (""), strrep does not replace empty character vectors or strings with the contents of new.