Concatenate cell and integer array horizontally

2 ビュー (過去 30 日間)
Amy Hassett
Amy Hassett 2020 年 4 月 14 日
コメント済み: Amy Hassett 2020 年 4 月 16 日
Hi all,
I have a structure (Group1_KOs), that contains a field (Behaviours) that are m*7 cell arrays. I have created a second structure (EventDuration) that consists of one field (Behaviours), which are m*1 integer arrays. I would like to concatenate these such that Group1_KOs.Behaviours is a m*8 cell array. I have tried coding it as follows, but to no avail:
Any help would be appreciated
for k= 1:size(Group1_KOs,2)
Group1_KOs(k).Behaviours = [Group1_KOs(k).Behaviours EventDuration(k).Behaviours];
end

採用された回答

Stephen23
Stephen23 2020 年 4 月 15 日
編集済み: Stephen23 2020 年 4 月 15 日
You will need to convert the integer array into a cell array, e.g. using num2cell:
for k = 1:size(Group1_KOs,2)
Group1_KOs(k).Behaviours = [Group1_KOs(k).Behaviours,num2cell(EventDuration(k).Behaviours)];
end % ^^^^^^^^^ ^
  1 件のコメント
Amy Hassett
Amy Hassett 2020 年 4 月 16 日
This worked, thanks!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by