Chage elements of a matrix

1 回表示 (過去 30 日間)
Berkay
Berkay 2022 年 8 月 30 日
回答済み: Chunru 2022 年 8 月 30 日
I have created a matrix filled with ones with this;
Matrix = ones(5,4)
And I want to change every second element of the matrix with random values how can I do it?

採用された回答

Chunru
Chunru 2022 年 8 月 30 日
Matrix = ones(5,4)
Matrix = 5×4
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
n = numel(Matrix);
Matrix(1:2:n) = randn(size(1:2:n))
Matrix = 5×4
-1.4989 1.0000 -0.9206 1.0000 1.0000 -0.8921 1.0000 1.2853 0.9458 1.0000 0.5612 1.0000 1.0000 -0.4176 1.0000 -0.7999 -0.3232 1.0000 -0.3478 1.0000

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNaNs についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by