placing elements of a cell array into a matrix

8 views (last 30 days)
I am reading in data from several files. For each file I first read the data into elements in a cell array. This works fine. I then want to place the elements of the cell array into a second matrix, where their position int eh second matrix depends on their position in the cell array. I can't seem to get this to work properly. My cell array is Nx1 and each element is a 2 column array with a variable number of rows. I would like the elements of the first column in the cell array at M to be appended to the second matrix at column M. to be more explicit..
say A is a 144X1 Cell array.
Say B is a 1X200 Matrix I would like to do something like
for m=1:length(A)
B(:,m)=[B(:,m);A{m}(:,1)]
end
does this make sense? It keeps giving me an index out o bounds error. I think that is because I am putting A{m}(:,1) into each row of A but I am not sure..
How can I do this? thanks for your help..

Answers (1)

Azzi Abdelmalek
Azzi Abdelmalek on 5 Mar 2013
out=[]
for m=1:length(A)
out=[out ; B';A{m}(:,1)]
end

Community Treasure Hunt

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

Start Hunting!