How to calculate mean of a cell which contains numbers and empty string?

I am working on cell in which there are 'NaN' values, along with the numbers. I need to calculate mean of 3x3 blocks after converting 'NaN' to empty string (''). I am doing this as I need mean of numbers only excluding 'NaN' entries, and '' are not counted while calculating mean. The error comes as 'mean()' can't be directly applied to cell, and I am unable to change the cell to matrix ('cell2mat'), as cell does not have all numbers but mix values.
See below for an example:
myCell ={ 1 2 3 4 5 NaN; 10 12 3 4 NaN NaN; NaN NaN NaN 1 4 5}
after replacing NaN by ''
myCell= { 1 2 3 4 5 ''; 10 12 3 4 '' ''; '' '' '' 1 4 5}
first 3x3 block is :
fisrtBlock = {1 2 3; 10 12 3; '' '' ''}
if I apply 'mean' after converting cell to matrix :
mean(cell2mat(firstBlock)),
the error is:
Error using cell2mat (line 46) All contents of the input cell array must be of the same data type.
if I try 'mean' directly: mean(firstBlock),
the error is:
Undefined function 'sum' for input arguments of type 'cell'.
Error in mean (line 28) y = sum(x)/size(x,dim);
if I try using 'cellfun':
f = cellfun(@mean, firstBlock),
the result is:
*f =
1 2 3
10 12 3
NaN NaN NaN*
I will appreciate any assistance for this problem. I am using MATLAB R2012a.

Answers (1)

To use cell2mat(A), all element of A should be the same class

2 Comments

@ Azzi, That for the reply.
I know that cell2mat() works if there are same class entries in cell, that's why I want to know if there is any other way to combine different type of elements (string , numbers) while calculating the mean.

Sign in to comment.

Tags

Asked:

on 12 Jun 2013

Community Treasure Hunt

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

Start Hunting!