placing elements of a cell array into a matrix

조회 수: 3 (최근 30일)
Jeff Spector
Jeff Spector 2013년 3월 5일
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에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by