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

Jan Orwat
Jan Orwat 2016년 6월 7일
편집: Jan Orwat 2016년 6월 7일
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})
does not. It works the same way for tables. Check categorical documentation for more information.
To solve this problem you may change numerical data to strings.
Stephen23
Stephen23 2016년 6월 7일
@Jan Orwat: you should put this as an answer: I would vote for it, and it might get accepted too.
Manuel Valenciano
Manuel Valenciano 2016년 6월 7일
편집: Manuel Valenciano 2016년 6월 7일
How can I change numerical data to strings?
idx = cellfun(@isnumeric,A);
Q = cellfun(@num2str,A(idx),'UniformOutput',false)
A(idx) = Q;
Manuel Valenciano
Manuel Valenciano 2016년 6월 8일
Thank you for your answer

댓글을 달려면 로그인하십시오.

 채택된 답변

Jan Orwat
Jan Orwat 2016년 6월 11일

1 개 추천

(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})
does not. It works the same way for tables. Check categorical documentation for more information.
To solve this problem you may change numerical data to strings.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Categorical Arrays에 대해 자세히 알아보기

질문:

2016년 6월 7일

답변:

2016년 6월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by