フィルターのクリア

Convert categorical back to integer

38 ビュー (過去 30 日間)
Steven Niggebrugge
Steven Niggebrugge 2019 年 12 月 22 日
回答済み: Eric Sofen 2020 年 1 月 10 日
Hi,
i convert an integer to a categorical
a=[-1 0 1]
b=categorical(a)
now how do i convert b back to the same integers in a?
Just can't find the function to do this.
thanks,
steven
  1 件のコメント
dpb
dpb 2019 年 12 月 22 日
>> str2num(char(b(:)))
ans =
-1
0
1
>>
But, not recommended; the underlying content of a categorical variable aren't really numeric even if they are numbers. The representation internally is an ordered set of the integers 1:N as I'm sure you've already discovered via double()
>> categories(b)
ans =
3×1 cell array
{'-1'}
{'0' }
{'1' }
>>
Gives the values of the categories that make up the unique elements but not the corresponding location in the original array.

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

回答 (1 件)

Eric Sofen
Eric Sofen 2020 年 1 月 10 日
Peter's answer to this similar post provides a few other suggestions to consider.

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by