placing elements of a cell array into a matrix

3 次查看(过去 30 天)
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..

回答(1 个)

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

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by