Could anyone help me how to change the values of the matrix to a desired range.

1 vue (au cours des 30 derniers jours)
jaah navi
jaah navi le 19 Juin 2021
Réponse apportée : Chunru le 19 Juin 2021
N = 10
X = zeros(N)
X(1:2,:) = 1
If i run the code i am getting the result as
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
but I want to have the result as
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
0 0 2 2 2 2 2 2 2 2
0 0 2 2 2 2 2 2 2 2
0 0 0 0 3 3 3 3 3 3
0 0 0 0 3 3 3 3 3 3
0 0 0 0 0 0 5 5 5 5
0 0 0 0 0 0 0 0 6 6
0 0 0 0 0 0 0 0 0 7
0 0 0 0 0 0 0 0 0 9
Could anyone please help me on this

Réponses (1)

Chunru
Chunru le 19 Juin 2021
Something like this:
N = 10
N = 10
X = zeros(N);
X(1:2,:) = 1;
X(3:4, 3:end)=2;
X(5:6, 5:end)=3;
X(7, 7:end)=5;
X(8, 9:end)=6;
X(9, 10)=7;
X(10,10)=9;
X
X = 10×10
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 2 2 2 2 2 2 2 2 0 0 2 2 2 2 2 2 2 2 0 0 0 0 3 3 3 3 3 3 0 0 0 0 3 3 3 3 3 3 0 0 0 0 0 0 5 5 5 5 0 0 0 0 0 0 0 0 6 6 0 0 0 0 0 0 0 0 0 7 0 0 0 0 0 0 0 0 0 9

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by