adding varied length vectors to a new matrix sequentially
Show older comments
I have a for loop which outputs a vector of varying length each time. I want to store each vector as a new row in a new matrix/array/structure (anything). I tried adding a line like this: temp1(:, i) = vec; with my vec to be stored going into a temp matrix. However, this does not work. Any tips on how I can achieve this?
Accepted Answer
More Answers (1)
Azzi Abdelmalek
on 20 Mar 2013
for k=1:10
vec=randi(10,1,randi(10),1) % your vector
out{k}=vec
end
2 Comments
mwa710
on 21 Mar 2013
Matt Tearle
on 21 Mar 2013
In general, you can access data in a cell array the same way: y = x{k} (then plot(y) or whatever). What exactly do you mean by a "raster plot"? This term seems to be context/application dependent. Can you describe the graph you're trying to make? I'm going to guess that you'll need to overlay plots using hold, if you're plotting a bunch of different-sized vectors. If so, you could do this inside the same for-loop that you're using to create/calculate the data in the first place.
Categories
Find more on Mathematics 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!