trying to combine cells

1 Ansicht (letzte 30 Tage)
nicolas
nicolas am 23 Mai 2013
I have 3 cells [1x5000] , [1x3000] and [1x2000] and I want to combine these in one cell [1x10000]. With small dimensions you can try the copy paste but now this is very slow procedure.
Do you have any ideas?
Thanks in advance!

Akzeptierte Antwort

Image Analyst
Image Analyst am 24 Mai 2013
Study this example:
% Original cell array, with 3 elements (cells).
ca = {ones(1,5000), rand(1,3000), zeros(1,2000)}
% Construct new cell with one element comprised of the
% contents of the other cell array's cells:
new_ca = {[ca{1}, ca{2}, ca{3}]}
Also, reading the FAQ may be helpful: http://matlab.wikia.com/wiki/FAQ#What_is_a_cell_array.3F
  2 Kommentare
Andrei Bobrov
Andrei Bobrov am 24 Mai 2013
new_ca = {cat(2,ca{:})};
new_ca = {[ca{:}]};
Image Analyst
Image Analyst am 24 Mai 2013
Bearbeitet: Image Analyst am 24 Mai 2013
nicolas said "Something like this,(I know that is wrong) C= [X(1, 1:5000),Y(1, 5001:8000), Z(1, 8001:10000)] Any ideas? "
Then just do this:
% Original cell array, with 3 elements (cells).
ca = {ones(1,99000), rand(1,99000), zeros(1,99000)}
% Construct new cell with one element comprised of certain specific elements
% of the contents of the other cell array's cells:
new_ca = {[ca{1}(1:5000), ca{2}(5001:8000), ca{3}(8001:10000)]}
If you have 3 separate cells instead of a cell array, then just concatenate them and use the same solution as above.
% Three separate original cells.
ca1 = {ones(1,99000)};
ca2 = {rand(1,99000)};
ca3 = {zeros(1,99000)};
% Combine, then use same solution as above.
ca = [ca1, ca2, ca3]
% Construct new cell with one element comprised of the
% contents of the other cell array's cells:
new_ca = {[ca{1}(1:5000), ca{2}(5001:8000), ca{3}(8001:10000)]}

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (5)

yagnesh
yagnesh am 24 Mai 2013
suppose x is [1x5000] , y is [1x3000] and z is [1x2000]
xyz=[x;y;z]

nicolas
nicolas am 24 Mai 2013
I think that there is a wrong in all of these answers, the way you described helps to create a new cell array, with contents the three cells, but no in a row. I mean that I would like to have in 5000 columns the first cell, the next 3000 columns the second etc.
Something like this,(I know that is wrong) C= [X(1, 1:5000),Y(1, 5001:8000), Z(1, 8001:10000)]
Any ideas? Thanks for your help!
  1 Kommentar
Image Analyst
Image Analyst am 24 Mai 2013
It's just one line - see my comment under my answer.

Melden Sie sich an, um zu kommentieren.


Andrei Bobrov
Andrei Bobrov am 24 Mai 2013
A = {X,Y,Z};
ii = hankel([0 5000],[5000 8000 10000]);
C = arrayfun(@(x)A{x}(ii(1,x)+1:ii(2,x)),1:numel(A),'un',0);
out = {[C{:}]};

nicolas
nicolas am 24 Mai 2013
It seems so somplicated! I don't know yet! I check this and I ll answer to you, thanks!
  2 Kommentare
Image Analyst
Image Analyst am 24 Mai 2013
Yes, cell arrays are almost always complicated. Can't you work with just normal old reliable numerical arrays? It would be so much simpler.
nicolas
nicolas am 24 Mai 2013
maybe, but now I have the data in this type, its wasted time to convert them. I just need an array with all of them in a row. Nevertheless thanks again, I ll try again tmrw

Melden Sie sich an, um zu kommentieren.


nicolas
nicolas am 29 Mai 2013
I know that it isn't so clever but finally I did it with (manual operated) "copy-paste" functions. http://www.mathworks.com/help/matlab/matlab_env/view-edit-and-copy-variables.html?searchHighlight=copy+paste+cells
Thanks for your time!

Kategorien

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

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by