How to linearly change values in matrix

2 ビュー (過去 30 日間)
Hanna Haponenko
Hanna Haponenko 2019 年 1 月 28 日
編集済み: Hanna Haponenko 2019 年 1 月 28 日
Observe this matrix:
thismatrix = eye(5)
thismatrix =
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
I wish to replace the zeros on either size of the 1's on every row with values descending from 1 by 0.1.
This is what I want:
thismatrix =
1.0000 0.9000 0.8000 0.7000 0.6000
0.9000 1.0000 0.9000 0.8000 0.7000
0.8000 0.9000 1.0000 0.9000 0.8000
0.7000 0.8000 0.9000 1.0000 0.9000
0.6000 0.7000 0.8000 0.9000 1.0000
How can I accomplish this without numerous "for loops"/spaghetti code (especially if my matrix is larger)?

採用された回答

Andrei Bobrov
Andrei Bobrov 2019 年 1 月 28 日
編集済み: Andrei Bobrov 2019 年 1 月 28 日
toeplitz(1:-.1:.6)
or
1 - abs((1:5) - (1:5)')*.1
  1 件のコメント
Hanna Haponenko
Hanna Haponenko 2019 年 1 月 28 日
編集済み: Hanna Haponenko 2019 年 1 月 28 日
Thank you kindly, Andrei

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by