Element replacement of matrix.

조회 수: 4 (최근 30일)
Usha Silwal
Usha Silwal 2019년 9월 11일
답변: David K. 2019년 9월 11일
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에서 NaNs에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by