how can i combine contents of two cell arrays into one cell array of same length
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
I have two cell arrays
Bill = {[1 2 3 4 5];[2 4 6 8 10]};
Ted = {[6 7 8 9 10];[12 14 16 18 20]};
and I want to merge them together so that
Excell = {[1 2 3 4 5 6 7 8 9 10]; [2 4 6 8 10 12 14 16 18 20]};
the only thing I can think of to combine them is
Excell = cellfun(@(v,w) [v,w],Bill,Ted,'UniformOutput',0)
but I imagine that there is a better more compact way to do this
thanks
0 Commenti
Risposta accettata
Geoff Hayes
il 14 Nov 2014
Joshua - I think that your solution works well. An alternative is the following
Excell = mat2cell(cell2mat([Bill , Ted]),[1 1]);
where we just combine the two cell arrays as [Bill , Ted] and then convert it to a 2x10 matrix with cell2mat. We then convert back to a cell array as mat2cell(...,[1 1]) where we use the [1 1] to indicate the row dimensions of the new cell array.
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Cell Arrays in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!