1
votes

When I import data from a database, I receive it as a cell. One row of the cell contains double values (such as 0.3421 0.5545 0.9199) and another row contains only int32 values (1 1 0). When I want to transform the whole cell with cell2mat, I get a mismatch error. If I use cell2mat on each row separately, I receive one matrix as double and one as int32. Is there a function being able to transform the whole cell to a matrix in double?

EDIT: I do not know beforehand which row is int32 and which is double, so it is not necessarily row 1 and 2. There are >50 rows

1
You can convert the second row to double and then concatenate: c = {3.2; int32(5)}; result = [cell2mat(c(1,:)); double(cell2mat(c(2,:)))] - Luis Mendo
Sorry, I now notice my description is incomplete. I do not know beforehand which row is in32 and which is double, so it is not necessarily row 1 and 2 - IltisGerry
Then convert both to double: result = [double(cell2mat(c(1,:))); double(cell2mat(c(2,:)))] - Luis Mendo
Or convert all values to doubles before calling cell2mat using cellfun. - Cris Luengo

1 Answers

1
votes

You can use cellfun to cast all data to doubles before using cell2mat:

a={int16(round(100*rand(100,1))), int32(round(100*rand(100,1)))}

b = cellfun(@double, a, 'uni', false);

cell2mat(b)