How to linearly change values in matrix

2 vues (au cours des 30 derniers jours)
Hanna Haponenko
Hanna Haponenko le 28 Jan 2019
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)?

Réponse acceptée

Andrei Bobrov
Andrei Bobrov le 28 Jan 2019
Modifié(e) : Andrei Bobrov le 28 Jan 2019
toeplitz(1:-.1:.6)
or
1 - abs((1:5) - (1:5)')*.1
  1 commentaire
Hanna Haponenko
Hanna Haponenko le 28 Jan 2019
Modifié(e) : Hanna Haponenko le 28 Jan 2019
Thank you kindly, Andrei

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Produits


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by