Storing vectors from a for loop, into a 2d matrix.
Show older comments
Greetings all,
Hopefully this is a relatively trivial issue, i have observed this short for loop:
>> for r = 1 : 10 vec = [10:20]+r mat(r,1) = vec end
which creates 10 vectors, e.g:
11 12 13 14 15 16 17 18 19 20 21
and stores them in a matrix like this:
11 12 13 14 15 16 17 18 19 20 21
12 13 14 15 16 17 18 19 20 21 22
13 14 15 16 17 18 19 20 21 22 23 ....etc
When i am trying to utilise this for my own project, i need it to be of the form:
for r = 1 : 5 : 16 vec = [10:20]+r mat(r,:) = vec end
which i thought would give:
11 12 13 14 15 16 17 18 19 20 21
16 17 18 19 20 21 22 23 24 25 26 etc.
But i am getting:
11 12 13 14 15 16 17 18 19 20 21
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
16 17 18 19 20 21 22 23 24 25 26
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
Where do all these 0's erupt from? i must plot the array without the zero's because my actual data is much larger (approx for k = 1: 500: 1000000) and exponential number of 0's just exceeds matlab capabilities.
anyone know a better way of storing these results in a 2d array? thank you, much obliged.
David
Accepted Answer
More Answers (0)
Categories
Find more on Monte Carlo Analysis 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!