MATLAB: Element replacement of matrix. matrix manipulation How do I replace each element in third row of the 5*4 matrix with its corresponding column number using for loop? Best Answer If using a for loop is not actually a requirement you can do this very simply as such:myMatrix = rand(5,4); % create 5x4 matrixmyMatrix(3,:) = 1:4; % replace valuesIf the for loop is a requirement:myMatrix = rand(5,4); % create 5x4 matrixfor n = 1:4 myMatrix(3,n) = n;end Related SolutionsMATLAB: How to Create a 5×5 matrix whose rows are (1:5) You can do that with simple vector multiplication:A = ones(5, 1) * (1:5); MATLAB: Deleting rows from array a(a(:,3)>5,:)=[]; Related QuestionRandom matrix with maximum values.Matrix manipulation and replacementsHow to replace the 3rd column element of a matrix by comparing 1st and 2nd column of another matrixHow i can create a n+1 column matrix from n column matrix
Best Answer