Concatenate cell and integer array horizontally

2 Ansichten (letzte 30 Tage)
Amy Hassett
Amy Hassett am 14 Apr. 2020
Kommentiert: Amy Hassett am 16 Apr. 2020
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

Akzeptierte Antwort

Stephen23
Stephen23 am 15 Apr. 2020
Bearbeitet: Stephen23 am 15 Apr. 2020
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 % ^^^^^^^^^ ^

Weitere Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by