# Cell array to double array?

조회 수: 11 (최근 30일)
L'O.G. 2022년 8월 25일
댓글: Walter Roberson 2022년 8월 25일
I have a cell array with each element a vector of type double. How do I convert this to an array of type double?

댓글을 달려면 로그인하십시오.

### 답변 (1개)

Walter Roberson 2022년 8월 25일
cell2mat — but first you might need to reshape() the cell. Sometimes you need to first use cellfun an anonymous function that reshapes the individual cells. It depends what the original sizes are and the target size.
##### 댓글 수: 2없음 표시없음 숨기기
L'O.G. 2022년 8월 25일
I should've mentioned the vector in each element of the cell array is of a different length, so I imagine cell2mat wouldn't be easy to use for this.
Walter Roberson 2022년 8월 25일
That is not necessarily a problem.
cell2mat does the equivalent of looping over the columns of the input cell and vertcat(CELL{:,COLUMN}) to produce numeric columns that it puts into cells. Then it loops over rows of that cell doing horzcat() of the expansion, producing 2d slices that it puts in cells. Then it loops over the 2d slices and stiches them together, and so on.
So for the first column of the input cell, it does not matter if the cell entries have different numbers of rows as long as they all have the same number of columns within each cell column. Then when it goes to put together the columns it only matters the total number of rows in each column added up.
For example, {1x2;3x2} is happy because the number of columns was consistent, producing a 4x2. If the second column of the cell input had been, {2x5;2x5} then columns consistent producing 4x5. And then in the second pass the 4x2 is row consistent with the 4x5 so 4x7 output.
Every entry of the cell input could be a different shape as long as the right dimension is consistent at the right time and the totals are consistent. You just have to be aware of the order everything is put together.

댓글을 달려면 로그인하십시오.

### 카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

R2021b

### Community Treasure Hunt

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

Start Hunting!

Translated by