adding elements from cell array to another
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Shivik Garg
am 12 Sep. 2017
Bearbeitet: James Tursa
am 12 Sep. 2017
i have cell array m [1x4] [1x5] and a cell array named y whose dimensions are [1x4] [1x5]. i want to put the y cell array into m such that resulting m is [1x8] [1x5] e.g
m{1}=2 3 6 44
m{2}= 12 34 25 66
and
y{1}=10 5 1 8
y{2}=3 0 9 6 7
resulting m should be
m{1}=2 3 6 44 10 5 1 8
m{2}=12 34 25 66 3 0 9 6 7
0 Kommentare
Akzeptierte Antwort
James Tursa
am 12 Sep. 2017
Bearbeitet: James Tursa
am 12 Sep. 2017
m = cellfun(@(A,B)[A B],m,y,'uni',false);
5 Kommentare
James Tursa
am 12 Sep. 2017
Bearbeitet: James Tursa
am 12 Sep. 2017
So, if m={} initially, then you can use the 2nd method above with the if-test. Just put that immediately prior to the cellfun call.
But, what do you mean by "generate y of different sizes"? Will y have a different number of cell elements on each iteration? E.g., is it possible that on one iteration y will have 2 vectors, but on another iteration if might have 5 vectors?
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Characters and Strings 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!