Unstack table and NaN values

3 ビュー (過去 30 日間)
Jose Rubio
Jose Rubio 2020 年 9 月 29 日
コメント済み: Star Strider 2020 年 10 月 1 日
I have a table with 5 columns which represent different variables
T = cell2table(MyArray,'VariableNames',{'ID' 'Region' 'Int_Den' 'Area' 'Group'});
Then, I used unstack to kind of reorganize it
S = unstack(T,'Int_Den','ID');
However, this is not exactly what I need. You can see from the screenshot below that I have a 294x52 table, where the majority of values are NaN. Instead of this, I would like to have a table where the first column is the "Region", and then the IDs will be distributed from columns 2 to 50. At the end the table should be 6 rows x 50 columns.
Thanks,
  1 件のコメント
Cris LaPierre
Cris LaPierre 2020 年 9 月 30 日
I think we need more more information about your table to help. Any chance you can attach a mat file containing T or MyArray?

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

採用された回答

Mohammad Sami
Mohammad Sami 2020 年 9 月 30 日
The remaining variables are used by unstack as grouping variables. You should exclude them when calling unstack.
T = cell2table(MyArray,'VariableNames',{'ID' 'Region' 'Int_Den' 'Area' 'Group'});
S = unstack(T(:,{'ID' 'Region' 'Int_Den'}),'Int_Den','ID');
  3 件のコメント
Mohammad Sami
Mohammad Sami 2020 年 10 月 1 日
Thanks :)
Star Strider
Star Strider 2020 年 10 月 1 日
Apparently, that got fixed!

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

その他の回答 (0 件)

カテゴリ

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