How to store all results in vector, after "for-.......-end" code?

2 views (last 30 days)
Hello, to all, many thanks for te possibility to learn more about MatLab through this forum and your shared experience! I would like to know how to store the individual results (which are arrays of 3x1 number) in the common array (vector with dimension of i*3x1). I am asking this because after "for-end" cycles only the last result is available fot further calculation. Any oppinion is highly appreciated! Regards!

Accepted Answer

Wayne King
Wayne King on 1 Mar 2012
Are you sure you don't want to save them as columns in a matrix like this:
N = 5;
X = zeros(3,5);
for nn = 1:5
X(:,nn) = randn(3,1);
end
If you really wanted them in one long column vector:
X = zeros(5*3,1);
for k = 0:4
X(k*3+1:(k+1)*3) = randn(3,1);
end

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!