MATLAB: How to genneral a repeat array repeat I have a array a = [1, 2 , 3 ,4], I want to repeat every element 3 times. The result is [1,1,1,2,2,2,3,3,3,4,4,4] Best Answer You can use repelem function to accomplish your questiona = 1 2 3 4>> repelem(a, 3)ans = 1 1 1 2 2 2 3 3 3 4 4 4 Related SolutionsMATLAB: How to repeat an element with different frequency You can do the following using 'repelem'. See the following: A = [1 2 3 4 5];B = [1 1 3 3 3];C = repelem(A, B)For more information, see the following documentation page: https://www.mathworks.com/help/matlab/ref/repelem.html#buqph3a MATLAB: How to replace half the number of specific element in an array To change random columns:>> A=[1 2 3 4 4 1 2 4 4 3 4 4 4 2 1 3 4 4 4 2 1 4 4]A = 1 2 3 4 4 1 2 4 4 3 4 4 4 2 1 3 4 4 4 2 1 4 4>> nnz(A==4)ans = 12>> idx = find(A==4);>> num = numel(idx);>> A(idx(randperm(num,ceil(num/2)))) = 2A = 1 2 3 2 2 1 2 4 4 3 2 4 2 2 1 3 2 4 4 2 1 2 4>> nnz(A==4)ans = 6 Related QuestionHow to repeat array withFrom a=[1 2 3 4] to b=[1 1 2 2 3 3 4 4]How can enlarge a matrixHi..i need to repeat rows and columns in matrix AHow to create the array [1, 2,2 ,3, 3, 3, 4,4 4, 4]
Best Answer