From: Derek Izuel on
Say I have a matrix of type double, of dimensions m x n, and a cell array of strings, dimensions 1 x n, holding the names of the columns of the matrix.

How do I use the dataset command to create a dataset from these variables, using the cell array as the column names.

I have tried dataset(<matrix>, <cellarray>), and dataset(<matrix>, 'VarNames', <cellarray>) and dataset({<matrix>, <cellarray>}). I keep getting an error that the number of variables and column names do not match.

Any help?

Thanks
From: Oleg Komarov on
"Derek Izuel" <derek.izuel(a)remove.thisuboc.com> wrote in message <i0ugfs$m1f$1(a)fred.mathworks.com>...
> Say I have a matrix of type double, of dimensions m x n, and a cell array of strings, dimensions 1 x n, holding the names of the columns of the matrix.
>
> How do I use the dataset command to create a dataset from these variables, using the cell array as the column names.
>
> I have tried dataset(<matrix>, <cellarray>), and dataset(<matrix>, 'VarNames', <cellarray>) and dataset({<matrix>, <cellarray>}). I keep getting an error that the number of variables and column names do not match.
>
> Any help?
>
> Thanks

In = rand(100,2);
varnames = {'name1','name2'};
dataset({In, varnames{:}}) % dataset({<matrix>, <cellarray{:}>}).

The dataset(<matrix>, 'VarNames', <cellarray>) doesn't work because it should be:
dataset(<vector1>,<vector2>,...,<vectorN> 'VarNames', <cellarray(1:N)>)

Oleg
 | 
Pages: 1
Prev: read mat file in C++
Next: read mat file in C++