splitvars for input arguments of type 'cell'

2 ビュー (過去 30 日間)
Deepa Maheshvare
Deepa Maheshvare 2019 年 11 月 24 日
コメント済み: Deepa Maheshvare 2019 年 11 月 24 日
The following contents are stored in a table, in variable 'tbl',
Multico value
______________
{'1'} {'2'} 1
{'2'} {'3'} 2
{'3'} {'4'} 1
{'4'} {'5'} 2
I am trying to split the contents in `Multico`
multico = splitvars(cell2mat(tbl.Multico));
The following error is obtained. Any suggestions on how to split the contents?
Undefined function 'splitvars' for input arguments of type 'cell'.
Expected result:
Multico_1 Multico_2 value
1 2 1
2 3 2
3 4 1
4 5 2
  2 件のコメント
Walter Roberson
Walter Roberson 2019 年 11 月 24 日
cell2mat() of that variable would give a 4 x 2 char array. splitvars() has to be run on a table and a variable name, not on a char array.
It is not obvious what you would want the result to be.
Deepa Maheshvare
Deepa Maheshvare 2019 年 11 月 24 日
編集済み: Deepa Maheshvare 2019 年 11 月 24 日
Many thanks for the reponse. Please have a look at the update made in the original post. Sorry if I wasn't clear. The contents are stored in a table. It is actually the output of the edge
properties of a graph (tbl = Graph.Edges).

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

採用された回答

Guillaume
Guillaume 2019 年 11 月 24 日
As per my comment to your other question, it looks like Multico should be a matrix not a cell array.
Regardless of its type, what you want is simply:
newtable = splitvars(yourtable, 'Multico')
  3 件のコメント
Guillaume
Guillaume 2019 年 11 月 24 日
Hum, splitvars works fine regardless of whether Multico is a cell array or a matrix:
>> t = table({'1', '2'; '2', '3'; '3', '4'; '4', '5'}, [1; 2; 1; 2], 'VariableNames', {'Multico', 'value'})
t =
4×2 table
Multico value
______________ _____
{'1'} {'2'} 1
{'2'} {'3'} 2
{'3'} {'4'} 1
{'4'} {'5'} 2
>> splitvars(t, 'Multico')
ans =
4×3 table
Multico_1 Multico_2 value
_________ _________ _____
{'1'} {'2'} 1
{'2'} {'3'} 2
{'3'} {'4'} 1
{'4'} {'5'} 2
>>
Deepa Maheshvare
Deepa Maheshvare 2019 年 11 月 24 日
Sorry, my mistake. I had tried splitvars(tbl.Multicol).

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by