MATLAB: Dataset arrays – extract and reconstruct variables

dataset arraymultiple variables

I'm trying to extract variables from multiple dataset arrays and compile them into a single dataset array that retains variable names – very straightforward. My problem is that the resulting array groups all input variables into the first column of the output array, rather than parsing each variable into individual columns. For example…
x = dataset({array1.var, array2.var, array3.var})
… returns a nx1 array with all variables grouped into the first column. Similarly….
varspec = ({array1.var,'var1', array2.var, var2', array3.var, 'var3'})
x = dataset(varspec)
… does the same.
Thoughts?

Best Answer

your notation is a little off
x=dataset({array1.var, 'var1'}, {arrray2.var, 'var2'}}
or if var is a string containing the name, then this
x=dataset({array1.var, var1}, {arrray2.var, var2}}
Loren has a very nice blog post on datasets that really helped me