フィルターのクリア

dataset arrays - extract and reconstruct variables

7 ビュー (過去 30 日間)
Sam
Sam 2013 年 4 月 3 日
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?

採用された回答

Leah
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 件のコメント
Sam
Sam 2013 年 4 月 3 日
Thanks, Leah. Yes, I knew my notation was off. I first attempted your suggestion but could not figure out how to break lines in my puny-sized editor window without matlab getting angry. '...' did the trick.
Loren's link is also helpful. Cheers.

サインインしてコメントする。

その他の回答 (1 件)

Peter Perkins
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.

カテゴリ

Help Center および File ExchangeTables についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by