No BSD License  

Highlights from
cell2num

2.2

2.2 | 5 ratings Rate this file 20 Downloads (last 30 days) File Size: 756 Bytes File ID: #15306

cell2num

by Darren

 

14 Jun 2007 (Updated 15 Jun 2007)

Used to convert 2 dimensional cell array of single numbers to a matrix.

| Watch this File

File Information
Description

Function to convert an all numeric cell array to a double precision array
********************************************
Usage:
outputmatrix=cell2num(inputcellarray)
********************************************
Output matrix will have the same dimensions as the input cell array
Non-numeric cell contest will become NaN outputs in outputmat
This function only works for 1-2 dimensional cell arrays of single numbers

Acknowledgements
This submission has inspired the following:
CELL2FLOAT
MATLAB release MATLAB 7.4 (R2007a)
Other requirements Should work on all platforms
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (8)
15 Jun 2007 John D'Errico

What purpose does this serve given the existence of cell2mat already in matlab? Also, this is limited to 1 or 2-d arrays, whereas cell2mat is not.

Finally, there is no error checking. You might argue that this (doubly looped) code checks for whether elements of the cell array are numeric or not, inserting NaNs there. But it still fails when the cell array elements are not scalar.

08 Aug 2007 Darren Brown

This function, although less powerful, is more tolerant than cell2mat because it can be used to extract numeric values from a cell array of mixed data types. Cell arrays are typically used to store strings along with numeric data. This function can retrieve just the numeric data.

24 Aug 2007 C Schwalm

Yes, this is a wonderful thing. I would prefer to see this functionality be integrated into CELL2MAT. But it is not. I often have to extract numeric contents from a cell array of cell arrays (particularly when using regexpi). This is handy.

24 Aug 2007 C Schwalm

I should add that I stumbled upon this looking for something else and that, to fully sastisfy my need to get at cell arrays of cell arrays with numeric values, I added

 elseif isnumeric(str2num(char(inputcell{r,c})));
            outputmat(r,c)=str2num(char(inputcell{r,c}));

to your if-then construct. Again, I'd love for this to be built-in or vectorized and welcome anything that barks up this tree like your submission.

21 Nov 2007 Mohammad Reza Jahanbin

slightly more compact version of the same thing which work for n-d arrays

cell2num = @(x) reshape(cat(1,x{:}), size(x));

/m

23 Apr 2008 Phillip Feldman

Very handy. This really should be part of the Matlab base.

22 Sep 2009 Kieran DSouza

The function must have been updated after the earlier reviews were written. This function is not working. I'm not sure why it would work. I just get a bunch of NaN's which is what I would expect after reading the code. The code returns NaN if the input cell is non-numeric. Since the input is a cell, it always returns NaN

13 Sep 2011 Lube F

Same here. Function is now pointless.

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
structures Darren 22 Oct 2008 09:15:41
cell arrays Darren 22 Oct 2008 09:15:41
cell conversion Darren 22 Oct 2008 09:15:41
cell2num Darren 22 Oct 2008 09:15:41
cell to numeric Darren 22 Oct 2008 09:15:41
cell array convert Darren 22 Oct 2008 09:15:41
numeri Darren 22 Oct 2008 09:15:41

Contact us at files@mathworks.com