trying to combine cells
조회 수: 1 (최근 30일)
이전 댓글 표시
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!
댓글 수: 0
채택된 답변
Image Analyst
2013년 5월 24일
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}]}
댓글 수: 2
Image Analyst
2013년 5월 24일
편집: Image Analyst
2013년 5월 24일
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)]}
추가 답변 (5개)
Andrei Bobrov
2013년 5월 24일
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{:}]};
댓글 수: 0
nicolas
2013년 5월 24일
댓글 수: 2
Image Analyst
2013년 5월 24일
Yes, cell arrays are almost always complicated. Can't you work with just normal old reliable numerical arrays? It would be so much simpler.
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!