How can I combine data from multiple cells into one matrix?

6 ビュー (過去 30 日間)
Katharine Wunsch
Katharine Wunsch 2016 年 3 月 21 日
コメント済み: Katharine Wunsch 2016 年 3 月 21 日
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!

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2016 年 3 月 21 日
A={rand(4,23) rand(5,23) rand(10,23)}
B=cell2mat(A')
  1 件のコメント
Katharine Wunsch
Katharine Wunsch 2016 年 3 月 21 日
This worked perfectly. Thank you!

サインインしてコメントする。

その他の回答 (1 件)

Image Analyst
Image Analyst 2016 年 3 月 21 日
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 件のコメント
Katharine Wunsch
Katharine Wunsch 2016 年 3 月 21 日
Oops, yes it is timecell, not initial data. Transposing worked, thank you!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by