How can I convert a cell array into a double array

조회 수: 1 (최근 30일)
Dan Park
Dan Park 2019년 2월 21일
편집: Andrei Bobrov 2019년 2월 21일
I would like to ask how to convert a set of cells (A{:}) in a cell array (A), to a set of double array.
A cell is let's say n by n cell, and the inner cell is m by m cell. In my case, I have 96 by 96 of A cell, and 5 of 1 by 5 cells for each cell in A cell array.
In this case, I would like to make the cellMatrix{1,3} into a double array, which becomes:
[0.1092 5.91663e-4 0 5.91663e-4 5.91663e-4;
5.91663e-4 0.0156 0.1044 0.0156 5.91663e-4;
0 0.1044 0.5570 0.1044 0 ;
5.91663e-4 0.0156 0.1044 0.0156 5.91663e-4;
0.1092 5.91663e-4 0 5.91663e-4 5.91663e-4;]
for every cell.
I have tried to use cell2mat(cellMatrix{:}), but it did not work.
It will be much appreciated for any help.

채택된 답변

Andrei Bobrov
Andrei Bobrov 2019년 2월 21일
편집: Andrei Bobrov 2019년 2월 21일
out = cell2mat(cellfun(@(x)cell2mat(cat(1,x{:})).',CellMatrix,'un',0));
  댓글 수: 1
Dan Park
Dan Park 2019년 2월 21일
편집: Dan Park 2019년 2월 21일
Thank you for you help Andrei,
This answer solves the problem. Could you please be so kind as to briefly describe the function 'cellfun(@(x))'?
From my understanding, this function calls each cell from a set of cells, and applies a function to it. Is my understanding correct?
Thank you again.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by