how to split a member of cell array

2 ビュー (過去 30 日間)
Sara
Sara 2018 年 10 月 1 日
回答済み: the cyclist 2018 年 10 月 1 日
I have a cell array of 100*1 and each member has the size of 5*700. what I want to do is split each member to 5 member of 1*700. So my output will be a cell number of 500*1 (5*100) and each member has the size of 1*700. I hope that I could clarify what I want to do.
thanks a lot
  2 件のコメント
the cyclist
the cyclist 2018 年 10 月 1 日
What class of object is the 5*700 contents of each cell? Is it a numeric array, another cell array, or something else?
Sara
Sara 2018 年 10 月 1 日
hello, It is numeric array.

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

採用された回答

Jan
Jan 2018 年 10 月 1 日
% Create some input data for testing ("InCell" is your input):
InCell = cell(100, 1);
for k = 1:100
InCell{k} = rand(5, 700);
end
OutCell = cell(500, 1);
a = 1;
b = 1;
for k = 1:500
OutCell{k} = InCell{a}(b, :);
b = b + 1;
if b > 5
a = a + 1;
b = 1;
end
end
This is the simply way using loops. Smarter:
Tmp = cat(1, InCell{:});
OutCell = num2cell(Tmp, 2);
  1 件のコメント
Sara
Sara 2018 年 10 月 1 日
Dear Jan,
Thanks for your help

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

その他の回答 (1 件)

the cyclist
the cyclist 2018 年 10 月 1 日
Another version of the loop, that is a little bit more intuitive to me:
OutCell = cell(500, 1);
for nc = 1:100
for nd = 1:5
OutCell{5*(nc-1)+nd} = InCell{nc}(nd,:);
end
end

カテゴリ

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

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by