How can I save 3 matrices created by for loop to save in a single matrix?
Show older comments
I have a for loop which outputs the following matrices after each iteration: [3,4;5,6], [8,5;2,4], [1,8;3,7]
I want to save these outputs into a single matrix and it should be this: final=[3,4;5,6;8,5;2,4;1,8;3,7]
The size of the 'final' matrix is known to me.
How do I do this?
Accepted Answer
More Answers (2)
deepak kumar
on 5 Jun 2018
a = [3,4,5,6]
b = [8,5;2,4]
c = [1,8;3,7]
d = vertcat(a,b,c)
or we can also do as temp =[]; for i =1:n %let say a have your output temp =[temp;a] end
Suraj Sudheer Menon
on 22 Jun 2020
0 votes
let x,y,z be the 3 iteration output vectors.
ans=[x ; y ; z]
% This creates a new vector by combining the above vectors. The semi colon indicates seperate rows(vertically joining).
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!