Info

Questa domanda è chiusa. Riaprila per modificarla o per rispondere.

changing specific values in diagonal

1 visualizzazione (ultimi 30 giorni)
A Aln
A Aln il 25 Mar 2019
Chiuso: MATLAB Answer Bot il 20 Ago 2021
Hello,
I'm trying to change the values in the diagonal based on its column.
let says this is my matrix ( 1/ ,2/ ,3/ ,4/ . . . . are the rows and columns number)
1/ 2/ 3/ 4/ 5/ 6/ 7/ 8/ 9/ 10/ 11/ 12/
1/ 1 1 0 0 1 0 0 0 0 0 0 0
2/ 1 1 1 0 0 1 0 0 0 0 0 0
3/ 0 1 1 1 0 0 1 0 0 0 0 0
4/ 0 0 1 1 0 0 0 1 0 0 0 0
5/ 1 0 0 0 1 1 0 0 1 0 0 0
6/ 0 1 0 0 1 1 1 0 0 1 0 0
7/ 0 0 1 0 0 1 1 1 0 0 1 0
8/ 0 0 0 1 0 0 1 1 0 0 0 1
9/ 0 0 0 0 1 0 0 0 1 1 0 0
10/ 0 0 0 0 0 1 0 0 1 1 1 0
11/ 0 0 0 0 0 0 1 0 0 1 1 1
12/ 0 0 0 0 0 0 0 1 0 0 1 1
in Diag (XX,-1), I want to change those values to 999:
1/ 2/ 3/ 4/ 5/ 6/ 7/ 8/ 9/ 10/ 11/ 12/
1/ 1 1 0 0 1 0 0 0 0 0 0 0
2/ 999 1 1 0 0 1 0 0 0 0 0 0
3/ 0 1 1 1 0 0 1 0 0 0 0 0
4/ 0 0 1 1 0 0 0 1 0 0 0 0
5/ 1 0 0 0 1 1 0 0 1 0 0 0
6/ 0 1 0 0 999 1 1 0 0 1 0 0
7/ 0 0 1 0 0 1 1 1 0 0 1 0
8/ 0 0 0 1 0 0 1 1 0 0 0 1
9/ 0 0 0 0 1 0 0 0 1 1 0 0
10/ 0 0 0 0 0 1 0 0 999 1 1 0
11/ 0 0 0 0 0 0 1 0 0 1 1 1
12/ 0 0 0 0 0 0 0 1 0 0 1 1
How to know which column to change ?
I defined those varibles:
x = 4
y = 3
I should change those:
column 1
column x+1
column 2x+1
The required:
How to do it? are there any different way to make it automatic for any matrix size?
  4 Commenti
KALYAN ACHARJYA
KALYAN ACHARJYA il 26 Mar 2019
mat=[1 1 0 0 1 0 0 0 0 0 0 0;1 1 1 0 0 1 0 0 0 0 0 0;
0 1 1 1 0 0 1 0 0 0 0 0;0 0 1 1 0 0 0 1 0 0 0 0;
1 0 0 0 1 1 0 0 1 0 0 0;0 1 0 0 1 1 1 0 0 1 0 0;
0 0 1 0 0 1 1 1 0 0 1 0;0 0 0 1 0 0 1 1 0 0 0 1;
0 0 0 0 1 0 0 0 1 1 0 0;0 0 0 0 0 1 0 0 1 1 1 0;
0 0 0 0 0 0 1 0 0 1 1 1;0 0 0 0 0 0 0 1 0 0 1 1];
[rows colm]=size(mat);
r1=2:4:rows;
c1=1:4:colm;
mat(r1,c1)=999 % Modification needed for individual elementwise pair of r1 and c2
Walter Roberson
Walter Roberson il 26 Mar 2019
ind = sub2ind(size(m), r1, c1);
mat(ind) = 999;

Risposte (1)

Image Analyst
Image Analyst il 26 Mar 2019
Sounds like homework. Some hints: check out toeplitz(), circshift(), and eye()

Prodotti


Release

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by