how to store the matrix from for loop?
Show older comments
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
Accepted Answer
More Answers (1)
Andrei Bobrov
on 1 Feb 2017
Edited: Andrei Bobrov
on 2 Feb 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 Comments
Stephen23
on 2 Feb 2017
+1 nice use of MATLAB.
Andrei Bobrov
on 2 Feb 2017
Thank you Stephen!
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!