Problem with categorical arrays
62 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Manuel Valenciano
am 7 Jun. 2016
Beantwortet: Jan Orwat
am 11 Jun. 2016
I have a problem with the categorical function. Some variables of my problem are of the following type (It is a reduced form of my problem):
I want to convert it to a categorical array but the categorical function gives me the following error:
Error using categorical (line 321)
Could not find unique values in DATA using the UNIQUE function.
Caused by:
Error using cell/unique (line 85)
Input A must be a cell array of strings.
This is the code I use for convert it in a categorical array.
VarA.VarA = categorical(VarA.VarA);
5 Kommentare
Brendan Hamm
am 7 Jun. 2016
idx = cellfun(@isnumeric,A);
Q = cellfun(@num2str,A(idx),'UniformOutput',false)
A(idx) = Q;
Akzeptierte Antwort
Jan Orwat
am 11 Jun. 2016
(Copied from comments as suggested.)
You are trying to make categorical array from a variable of mixed data types.
categorical([1 2 3 5 2 1])
categorical({'str1' 'str2'})
works, but
categorical({'str1' 'str2' 1 3 2 1})
To solve this problem you may change numerical data to strings.
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Categorical Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!