Element replacement of matrix.

3 ビュー (過去 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 Center および File ExchangeGet Started with MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by