How can I combine data from multiple cells into one matrix?
Mostrar comentarios más antiguos
I have a cell that contains 233 matrices, each with data in it. I would like to pull all of this data into one matrix with 23 columns, however I run into problems because each matrix does not have the same number of rows, though they all have 23 columns. This code pulls most of the data into the matrix, but still overwrites some lines when multiple columns are being added from the same matrix.
load('initialdata.mat'); %1x233 cell
k=length(initial data);
for i=1:k
finaldata = zeros(23,500); %500 is arbitrary
m=1
z=0
for j = 1:500
j = m
[row column] = find(timecell{1,j});
if length(row) == 23
z= 1
for i = 1:23
finaldata(i,j) = (timecell{1,j}(1,i));
end
elseif length(row) > 23
for z = 1:length(row)/23
for i = 1:23
finaldata(i,j+z) = (timecell{1,j}(z,i));
end
end
elseif length(row) == 0;
z= 0
end
m = j+z
end
end
Thank you!
Respuesta aceptada
Más respuestas (1)
Image Analyst
el 21 de Mzo. de 2016
What is your cell array called? "initial data" is not a valid variable name so don't know how that got past the length() call. Is it timecell? Did you try something like
finaldata = timecell{:};
If that doesn't work, maybe try transposing timecell. Otherwise go down cell by cell concatenating with a semicolon
for k = 1 : length(timecell)
if k == 1
finaldata = timecell{k};
else
finaldata = [finaldata; timecell{k}];
end
end
1 comentario
Katharine Wunsch
el 21 de Mzo. de 2016
Categorías
Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!