MATLAB: Changing value when first time a value appears arrayindexindexingnanvariablevariables A=[1; 1; 1; 1; 2; 2; 4; 4; 4; 4] B=[4; 2; 7; 9; 5; 0; 2; 6; 1; 0] I want to change the values of B to NaN whenever a value in A appears for the first time. i.e. B=[NaN; 2; 7; 9; NaN; 0; NaN; 6; 1; 0] Best Answer A=[1; 1; 1; 1; 2; 2; 4; 4; 4; 4]A = 10×1 1 1 1 1 2 2 4 4 4 4 B=[4; 2; 7; 9; 5; 0; 2; 6; 1; 0]B = 10×1 4 2 7 9 5 0 2 6 1 0 [~, ia] = unique(A, 'stable')ia = 3×1 1 5 7 B(ia) = nanB = 10×1 NaN 2 7 9 NaN 0 NaN 6 1 0 Related SolutionsMATLAB: Help running Matlab scriptMATLAB: Count number of values between NaN In = [NaN; NaN; NaN; NaN; 1; 1; 1; 1; NaN; NaN; NaN; 1; NaN; NaN; NaN; NaN; NaN; NaN; NaN; 1; NaN; NaN; NaN; NaN];[a,b] = rude(~isnan(In));a(b)rude is on the FEX Related QuestionHow to superimpose three matrixHow to select or group sections of an array without using indexingElimination of the chosen elements and rearranging the matrixHow to select a part of an array between NaN valuesHow to sort matrix based on another matrixSimil to VLOOKUP (but ismember index 0)
Best Answer