From: Andres Klever on
i want to do the conversion cell2mat, but the problem is that the guy that i want to convert has '[]' empty components in some cells, and numeric data in the rest of them, so i have this error:

All contents of the input cell array must be of the same data type

i cannot change the '[]' for 0 because i need to read 0 as number. so if anybody has a solution for this please help,

thanks a lot!


From: Nathan on
On Sep 8, 12:09 pm, "Andres Klever" <andis...(a)gmail.com> wrote:
> i want to do the conversion cell2mat, but the problem is that the guy that i want to convert has '[]' empty components in some cells, and numeric data in the rest of them, so i have this error:
>
> All contents of the input cell array must be of the same data type
>
> i cannot change the '[]' for 0 because i need to read 0 as number. so if anybody has a solution for this please help,
>
> thanks a lot!

How about replacing [] with NaN?
A = {1 [] 2 3 [] 4 5};
A(cellfun('isempty',A)) = {NaN};
cell2mat(A);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ans =
1 NaN 2 3 NaN 4 5

-Nathan
From: Andres Klever on
Nathan <ngreco32(a)gmail.com> wrote in message <d67caaf9-8585-4dad-a6aa-5b9cdf015dc4(a)m3g2000pri.googlegroups.com>...
> On Sep 8, 12:09?pm, "Andres Klever" <andis...(a)gmail.com> wrote:
> > i want to do the conversion cell2mat, but the problem is that the guy that i want to convert has '[]' empty components in some cells, and numeric data in the rest of them, so i have this error:
> >
> > All contents of the input cell array must be of the same data type
> >
> > i cannot change the '[]' for 0 because i need to read 0 as number. so if anybody has a solution for this please help,
> >
> > thanks a lot!
>
> How about replacing [] with NaN?
> A = {1 [] 2 3 [] 4 5};
> A(cellfun('isempty',A)) = {NaN};
> cell2mat(A);
> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
> ans =
> 1 NaN 2 3 NaN 4 5
>
> -Nathan



ok, thanks that worked perfectly,
 | 
Pages: 1
Prev: Combining histogram and plot
Next: Solve Equation