how to store the matrix from for loop?
Afficher commentaires plus anciens
m=3;
A=[ 1 1 0];
B=[0 1 0];
D=B-A;
d1=m*A;
for X=0:1:m
C=d1+D*X
end
Réponse acceptée
Plus de réponses (1)
Andrei Bobrov
le 1 Fév 2017
Modifié(e) : Andrei Bobrov
le 2 Fév 2017
m=3;
A=[ 1 1 0];
B=[0 1 0];
D=B-A;
d1=m*A;
C = d1 + (0:m)'*D; % R2016b and later
C = bsxfun(@plus,d1,(0:m)'*D); % R2016a and earlier
2 commentaires
Stephen23
le 2 Fév 2017
+1 nice use of MATLAB.
Andrei Bobrov
le 2 Fév 2017
Thank you Stephen!
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!