From: Lecho Vergara on
Hi guys
I have 10000x1 cell array 'table'. Some of these cells are empty values([]), so lets say isempty(table{983}) returns true but in general most of them contain numeric values and is not empty. I want to convert this cell array to matrix but if I do:
matrix=cell2mat(table);
then the resulting matrix has less number of elements, lets say 99800, and this is due to assignment of empty values. I want to have NaNs in 'matrix' when there
are empty values in 'table' so I can get as a result a matrix of the same dimension(10000) as the original. How can this be accomplished? I thought to patch the
original table writing NaNs in empty cell array positions but when I try to find these positions:
mask=isempty(table{:})
i get
??? Error using ==> isempty
Too many input arguments.
What do you suggest?
From: Steven Lord on

"Lecho Vergara" <nothin(a)nothing.com> wrote in message
news:hq4f2t$i1j$1(a)fred.mathworks.com...
> Hi guys
> I have 10000x1 cell array 'table'. Some of these cells are empty
> values([]), so lets say isempty(table{983}) returns true but in general
> most of them contain numeric values and is not empty. I want to convert
> this cell array to matrix but if I do:
> matrix=cell2mat(table); then the resulting matrix has less number of
> elements, lets say 99800, and this is due to assignment of empty values. I
> want to have NaNs in 'matrix' when there
> are empty values in 'table' so I can get as a result a matrix of the same
> dimension(10000) as the original. How can this be accomplished? I thought
> to patch the original table writing NaNs in empty cell array positions but
> when I try to find these positions:
> mask=isempty(table{:}) i get ??? Error using ==>
> isempty
> Too many input arguments. What do you suggest?

Use CELLFUN to locate the empty cells, then fill those cells in with NaNs
and finally concatenate them all together.

C = {1, 2, [], 4};
locateEmpty = cellfun(@isempty, C);
C(locateEmpty) = {NaN}; % or [C{locateEmpty}] = NaN;
M = [C{:}]

--
Steve Lord
slord(a)mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ


 | 
Pages: 1
Prev: Thank you
Next: geometrical object recognition