Changing elements with a condition
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
James Tursa
le 21 Déc 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);
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!