convert a cell into a double in matlab

You can convert a cell containing a single value to a double using the following function:

main.m
cell_data = {'10'}; % cell containing single value
double_data = str2double(cell_data{1}); % convert cell to double
116 chars
3 lines

Here, str2double is used to convert the string in the cell to double. cell_data{1} is used to access the string in the first (and only) element of the cell array. The resulting double is stored in double_data.

Note that if the cell contains multiple values, you will need to loop over the cell array and convert each value individually. If the cell contains non-numeric data, str2double will return NaN (not a number).

related categories

gistlibby LogSnag