calling unique function on a string column of a table failed
이전 댓글 표시
I have a simple table (say, T) one column (say C) of which is a string column. [v, u] = unique({T.C}) fails with the exception:
Cell array input must be a cell array of character vectors.
댓글 수: 7
Stephen23
2023년 5월 1일
[v, u] = unique({T.C})
% ^ ^ get rid of these
Enping
2023년 5월 2일
Probably related, the existing script also has code like T(i).C. Now such code causes the error "Dataset array subscripts must be two-dimensional."
You have the ability to demonstrate that for us here directly by attaching T in a .mat file to your post and running the line of code that produces the error. That will allow us all to examine exactly what is happening. It doesn't really make sense that you are getting error messages referring to T as a "dataset" variable when in your OP, you said T was a table.
The dataset class is a table-like class, the precursor for table arrays, introduced in Statistics and Machine Learning Toolbox in release R2007a. [We recommend using table arrays instead of dataset arrays and have for several releases.] It behaves much like a table array and so colloquially calling it a "table" seems reasonable (even though technically it's not a table.)
The equivalent error for a table array would be (using try / catch and warning so I can run further code in the comment):
T = array2table(magic(4));
try
y = T(1)
catch ME
warning(ME.message)
end
I don't think this type of indexing operation ever worked for either table or dataset.
In general, if you're working with string data you should operate on string arrays rather than cell arrays containing string arrays.
nephews = ["Huey"; "Dewey"; "Louie"] % Preferred
nephewsC = {"Huey"; "Dewey"; "Louie"}
Enping
2023년 5월 2일
@Enping this is now a very different question, having to do with dataset objects and nothing to do with table objects and unique() as you originally posted. Therefore, you should ask about dataset object indexing in a different thread, hopefully after accept-clicking the answer I have put below, which does address your original question.
Enping
2023년 5월 2일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Data Type Identification에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!