Element replacement of matrix.

3 次查看(过去 30 天)
How do I replace each element in third row of the 5*4 matrix with its corresponding column number using for loop?

采纳的回答

David K.
David K. 2019-9-11
If using a for loop is not actually a requirement you can do this very simply as such:
myMatrix = rand(5,4); % create 5x4 matrix
myMatrix(3,:) = 1:4; % replace values
If the for loop is a requirement:
myMatrix = rand(5,4); % create 5x4 matrix
for n = 1:4
myMatrix(3,n) = n;
end

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by