How to assign a constant to a submatrix without a loop
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Is this possible without a for loop? Sample code:
%A is an (m x n) matrix m,n > 2
A(2:end-1,2) = 67.5*ones(size(A(2:end-1,2)));
I so far can not make this work.
1 commentaire
Adam Danz
le 29 Avr 2020
Modifié(e) : Adam Danz
le 30 Avr 2020
What's the problem with the code in your question other than that it can be simplified (see answer)?
A =
5 4 9 2 8 8
1 6 1 10 7 3
2 5 8 4 4 8
8 6 1 10 9 6
6 9 3 2 5 7
>> A(2:end-1,2) = 67.5*ones(size(A(2:end-1,2)))
A =
5 4 9 2 8 8
1 67.5 1 10 7 3
2 67.5 8 4 4 8
8 67.5 1 10 9 6
6 9 3 2 5 7
Réponse acceptée
Adam Danz
le 29 Avr 2020
Modifié(e) : Adam Danz
le 4 Mai 2020
A = magic(9) % demo matrix
A(2:end-1,2) = 67.5;
result
A(2:end-1,2) = 67.5
A =
47 58 69 80 1 12 23 34 45
57 67.5 79 9 11 22 33 44 46
67 67.5 8 10 21 32 43 54 56
77 67.5 18 20 31 42 53 55 66
6 67.5 19 30 41 52 63 65 76
16 67.5 29 40 51 62 64 75 5
26 67.5 39 50 61 72 74 4 15
36 67.5 49 60 71 73 3 14 25
37 48 59 70 81 2 13 24 35
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Multirate Signal Processing 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!