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!