フィルターのクリア

How to convert nominal variable to number?

8 ビュー (過去 30 日間)
Tom Salomon
Tom Salomon 2018 年 5 月 15 日
回答済み: Andrei Bobrov 2018 年 5 月 15 日
I have a nominal variable which I would like to convert to double. Just using 'double' function won't work. I found a workaround by first converting the nominal variable to string (then 'str2num' works). I was wondering is there a more elegant 'str2double' style function to convert nominal to double? Also - why str2num works whereas str2double fails to convert appropriately?
double_var = [10,20,30];
nominal_var = nominal(double_var);
back2double_1 = double(nominal_var); % wrong
back2double_2 = str2num(char(nominal_var)); % workaround that works
back2double_3 = str2double(char(nominal_var)); % workaround that doesn't work

回答 (1 件)

Andrei Bobrov
Andrei Bobrov 2018 年 5 月 15 日
str2double(string(nominal_var))

カテゴリ

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

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by