필터 지우기
필터 지우기

convert cell array to 3d array

조회 수: 2 (최근 30일)
lucksBi
lucksBi 2017년 4월 14일
댓글: lucksBi 2017년 4월 14일
i have cell array which contains multiple elements like this: a={2x1 cell,2x1 cell,2x1 cell;3x1 cell,3x1 cell,3x1 cell}
and every cell contains elements like for example for first row elements are like this:
a{1,1}{1,1}=2
a{1,1}{2,1}=2
a{1,2}{1,1}=1
a{1,2}{2,1}=1
a{1,3}{1,1}=1
a{1,3}{2,1}=-1
i want to convert this cell array into a 3D array. i have tried cell2mat but it gives following error:
"CELL2MAT does not support cell arrays containing cell arrays or objects"
please help.

채택된 답변

Stephen23
Stephen23 2017년 4월 14일
편집: Stephen23 2017년 4월 14일
Assuming that all numeric arrays are of a size that can be concatenated together:
>> cell2mat(cellfun(@cell2mat,a,'uni',0))
ans =
2 1 1
2 1 -1
You can then use reshape to arrange the data into a 3D array. Or alternatively, use reshape or permute on the intermediate cell array:
cell2mat(permute(cellfun(@cell2mat,a,'uni',0),[1,3,2]))
As you did not state how you want the dimensions rearranged, it is hard to give more advice than that.
  댓글 수: 2
lucksBi
lucksBi 2017년 4월 14일
Thankyou for your answer. But it gives following error.
Error using cat
Dimensions of matrices being concatenated are not consistent.
lucksBi
lucksBi 2017년 4월 14일
i want answer in this form:
2 1 1
2 1 -1

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by