How can I create a dataset from individual columns of a matrix and name them in MATLAB 7.8 (R2009a)?

1 view (last 30 days)
I have a matrix of data. I want to create a dataset with the individual columns of this matrix set to separate variables with specific names.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 15 Sep 2009
To create a dataset with variables made up of columns of a matrix, you can use the MAT2CELL function to break up the matrix into individual columns, and pass it to the dataset constructor. For example see code below:
z = rand(10,10);
names = {'varA', 'varB', 'varC', 'varD', 'varE', ...
'varF', 'varG', 'varH', 'varI', 'varJ'};
Z = mat2cell(z, size(z,1), ones(size(z,2), 1));
ds = dataset(Z{:}, 'VarNames', names);

More Answers (0)

Products


Release

R2009a

Community Treasure Hunt

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

Start Hunting!