dataset arrays - extract and reconstruct variables
7 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
采纳的回答
Leah
2013-4-3
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
更多回答(1 个)
Peter Perkins
2013-4-4
Sam, it may be that you want to combine variables with the same name from different arrays. If that's the case, then something similar to what you're doing is probably the way to go, though I'd do it slightly differently:
x = dataset(array1.var,array2.var,..., 'VarNames',{'var1' 'var2' ...})
But if the variables you're combining already have different names, then I think you'd be better off just using concatenation:
x = [array1(:,'var1') array2(:,'var2') ...]
Hope this helps.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!