cell array to vector using cell2mat

조회 수: 29 (최근 30일)
shobhit mehrotra
shobhit mehrotra 2015년 2월 15일
답변: Stephen23 2015년 2월 15일
I have a cell array {C} =1x12, with each cell consisting of only integers. All cells have different amounts of data
cell 1: [1 3 6 7]
cell 2: [ 6 7 12 34 33 66]
etc.
I want to create a vector
V = [ cell 1 cell 2....cell 12]
V= [ 1 3 6 7 6 7 12 34 33 66]
Thanks

채택된 답변

Stephen23
Stephen23 2015년 2월 15일
Some alternatives:
V = cell2mat(C);
V = [C{:}];
V = horzcat(C{:});
V = cat(2,C{:});
Each of these can be adapted different for different situations, so it is useful to know similar (but different) way of achieving this.

추가 답변 (1개)

dpb
dpb 2015년 2월 15일
You answered the question in the title...
>> c
c =
[1x4 double] [1x6 double]
>> cell2mat(c)
ans =
1 3 6 7 6 7 12 34 33 66
>>
What's the reason for the question or did you just not try it out of uncertainty?

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by