Changing elements with a condition

3 visualizaciones (últimos 30 días)
Onur Güven
Onur Güven el 21 de Dic. de 2018
Comentada: Onur Güven el 21 de Dic. de 2018
Hi all,
I've some basic questions about changing the elements of a 9x9 matrix with a specific condition. The matrix is;
X1 =
0 0 0 0 0 0 0 0 0
0.2778 0.2800 0 0 0 0 0 0 0
0.2222 0.2000 0.3700 0 0 0 0 0 0
0.1333 0.1600 0.1750 0.4600 0 0 0 0 0
0.0889 0.0960 0.1400 0.1500 0.5950 0 0 0 0
0.0667 0.0640 0.0840 0.1200 0.1125 0.5950 0 0 0
0.0611 0.0480 0.0560 0.0720 0.0900 0.1125 0.6400 0 0
0.0444 0.0440 0.0420 0.0480 0.0540 0.0900 0.1000 0.6400 0
0.0222 0.0320 0.0385 0.0360 0.0360 0.0540 0.0800 0.1000 0.6400
And I want to create X2 as
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0.278 0.280 0 0 0 0 0 0
0 0.222 0.200 0.370 0 0 0 0 0
0 0.133 0.160 0.175 0.460 0 0 0 0
0 0.089 0.096 0.140 0.150 0.595 0 0 0
0 0.067 0.064 0.084 0.120 0.113 0.595 0 0
0 0.061 0.048 0.056 0.072 0.090 0.113 0.640 0
0 0.044 0.044 0.042 0.048 0.054 0.090 0.100 0.640
And X3 as
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.278 0.280 0 0 0 0 0
0 0 0.222 0.200 0.370 0 0 0 0
0 0 0.133 0.160 0.175 0.460 0 0 0
0 0 0.089 0.096 0.140 0.150 0.595 0 0
0 0 0.067 0.064 0.084 0.120 0.113 0.595 0
0 0 0.061 0.048 0.056 0.072 0.090 0.113 0.640
Thanks to everyone for solution.
;
  2 comentarios
Rik
Rik el 21 de Dic. de 2018
You mean you want to make a copy and assign zeros to specific rows and columns?
Onur Güven
Onur Güven el 21 de Dic. de 2018
yes.

Iniciar sesión para comentar.

Respuesta aceptada

James Tursa
James Tursa el 21 de Dic. de 2018
clear X2 X3
[m,n] = size(X1);
X2(2:m,2:n) = X1(1:m-1,1:n-1);
X3(3:m,3:n) = X1(1:m-2,1:n-2);

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Productos


Versión

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by