How can we insert a row matrix without altering the rest of the values?
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Ashfaq Ahmed
le 2 Déc 2022
Commenté : Ashfaq Ahmed
le 2 Déc 2022
Hi!
Say, I have this matrix -
A =
1 2 3
4 5 6
7 8 9
10 11 12
13 14 15
Now I want to add A*10 after each of the rows so that I can make this matrix -
A =
1 2 3
10 20 30
4 5 6
40 50 60
7 8 9
70 80 90
10 11 12
100 110 120
13 14 15
130 140 150
I have hundreds of rows, so I would prefer a loop (or anything!)
Thank you for your help.
0 commentaires
Réponse acceptée
Dyuman Joshi
le 2 Déc 2022
Modifié(e) : Dyuman Joshi
le 2 Déc 2022
A = reshape(1:15,3,5)'
%pre-allocation
y=zeros(size(A,1)*2,size(A,2));
y(1:2:end,:)=A;
y(2:2:end,:)=A*10
Plus de réponses (1)
Fangjun Jiang
le 2 Déc 2022
Modifié(e) : Fangjun Jiang
le 2 Déc 2022
A=magic(3);
C=transpose(reshape([A,10*A]',size(A,1),[]))
0 commentaires
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!