convert cell 2 double with a table inside

I have a matrix A containing cell array 12x1 which has table inside with dimension 86400x24 in each cell.
I would like to convert this matrix A to double. Is there any way?
Please note I want to keep the cells and hence table concantenated in the output. I do not wish to convert each
cell individually. I want to convert matrix A

댓글 수: 4

madhan ravi
madhan ravi 2018년 12월 10일
cell2mat()?
Megha
Megha 2018년 12월 10일
Error using cell2mat (line 52)
CELL2MAT does not support cell arrays containing cell arrays or objects.
madhan ravi
madhan ravi 2018년 12월 10일
so upload your data as .mat file
Guillaume
Guillaume 2018년 12월 13일
A cell array is not a matrix.
A table is not a matrix either.
Do you want to:
  • convert each table into matrices (assuming every variable of the table is numeric) and then concatenate the whole lot vertically?
  • or simply concatenate all the tables into a single table (assuming all the tables have the same variables)

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

답변 (1개)

Astha Singh
Astha Singh 2018년 12월 13일

1 개 추천

Based on the information provided, I can suggest you to employ a for-loop to convert each table to an array, using the function 'table2array()', and keep concatenating it to your desired matrix. Look at the following code for example:
fin_mat = [];
for =1:length(c)
fin_mat = [fin_mat ; table2array(c{i})];
end
Here, 'c' is the cell array of tables.

댓글 수: 3

Personally I'd do it like this:
%A: cell array where each cell is a table:
Amatrices = cellfun(@table2array, A, 'UniformOutput', false);
Afinal = vertcat(Amatrices{:});
Stephen23
Stephen23 2018년 12월 13일
@Astha Singh: expanding numeric arrays within loops is not efficient, and the MATLAB documentation recommends using more efficient ways to write code:
This can be easily avoided in this case e.g. placing the data into a preallocated cell array and concatenating after the loop, or using cellfun as Guillaume showed.
Astha Singh
Astha Singh 2018년 12월 14일
Sure. Thanks, I missed that.

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

카테고리

도움말 센터File Exchange에서 Data Type Conversion에 대해 자세히 알아보기

질문:

2018년 12월 10일

댓글:

2018년 12월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by