Creating a certain array
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi I want to create a 10 by 10 array and replace its values. If the said value is at 1,1 / 3,1 / etc. where combination of 2 values of its rows and columns make an even number I want it to be 10 and if its 2,1 / 1,4 etc. I want it to be 20. Any idea how I can achieve that? I guess i should check the combination of row and column numbers for divisibility by 2 but I couldn't find how.
0 commentaires
Réponse acceptée
Jan
le 23 Juin 2021
Modifié(e) : Jan
le 23 Juin 2021
v = rem(1:10, 2);
M = 10 + 10 * (v ~= v.')
Or with linear indexing:
M = 10 * ones(9);
M(2:numel(M)) = 20;
The 1st method works with all sizes of the matrox, while the 2nd method needs an odd number of rows, so it does not work with n=10.
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Matrox Hardware 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!