problem with cell array e unique

4 次查看(过去 30 天)
>> class(RankList)
ans =
'cell'
>> typeRank=unique(cell2table(RankList))
Error using tabular/unique
Unable to group rows using unique values of the table variable 'RankList'. UNIQUE returned an error.
Caused by:
Error using matlab.internal.math.uniqueCellstrHelper
Cell array input must be a cell array of character vectors.

采纳的回答

Star Strider
Star Strider 2023-8-30
There are 9 empty cells in ‘RankList’ and they were causing the problem.
Try this —
LD = load('matlab_RankList.mat')
LD = struct with fields:
RankList: {351×1 cell}
RankList = LD.RankList
RankList = 351×1 cell array
{'AD_Multiday_Reversal'} {'BP_Multiday_Bias' } {'BP_Multiday_Reversal'} {'BP_Multiday_Reversal'} {'BP_Multiday_Reversal'} {'BP_Intraday_Reversal'} {'BP_Multiday_Reversal'} {'BP_Multiday_Trend' } {'BP_Multiday_Reversal'} {'BP_Multiday_Reversal'} {'BP_Intraday_Reversal'} {'CC_Multiday_Bias' } {'CL_Intraday_Bias' } {'CL_Intraday_Trend' } {'CL_Intraday_Bias' } {'CL_Intraday_Trend' }
idx = cellfun(@(x)~isempty(x), RankList); % Logical Vector
Empty_Cells = nnz(~idx)
Empty_Cells = 9
RankListFull = RankList(idx) % Non-Empty Entries
RankListFull = 342×1 cell array
{'AD_Multiday_Reversal'} {'BP_Multiday_Bias' } {'BP_Multiday_Reversal'} {'BP_Multiday_Reversal'} {'BP_Multiday_Reversal'} {'BP_Intraday_Reversal'} {'BP_Multiday_Reversal'} {'BP_Multiday_Trend' } {'BP_Multiday_Reversal'} {'BP_Multiday_Reversal'} {'BP_Intraday_Reversal'} {'CC_Multiday_Bias' } {'CL_Intraday_Bias' } {'CL_Intraday_Trend' } {'CL_Intraday_Bias' } {'CL_Intraday_Trend' } {'CL_Intraday_Reversal'} {'CL_Multiday_Trend' } {'CL_Multiday_Trend' } {'CL_Intraday_Trend' } {'CL_Intraday_Bias' } {'CL_Intraday_Bias' } {'CL_Intraday_Bias' } {'CL_Intraday_Bias' } {'CL_Intraday_Trend' } {'CL_Intraday_Reversal'} {'CL_Intraday_Trend' } {'CL_Multiday_Trend' } {'CL_Multiday_Reversal'} {'CL_Intraday_Trend' }
RankListUnique = unique(RankListFull) % Unique Entries (Sorted)
RankListUnique = 90×1 cell array
{'AD_Multiday_Reversal' } {'BP_Intraday_Reversal' } {'BP_Multiday_Bias' } {'BP_Multiday_Reversal' } {'BP_Multiday_Trend' } {'CC_Multiday_Bias' } {'CL_Intraday_Bias' } {'CL_Intraday_Reversal' } {'CL_Intraday_Trend' } {'CL_Multiday_Reversal' } {'CL_Multiday_Trend' } {'C_Multiday_Trend' } {'EC_Intraday_Bias' } {'EC_Intraday_Reversal' } {'EC_Intraday_Trend' } {'EC_Multiday_Reversal' } {'EC_Multiday_Trend' } {'ES_Intraday_Bias' } {'ES_Intraday_Reversal' } {'ES_Intraday_Trend' } {'ES_Multiday_Bias' } {'ES_Multiday_Reversal' } {'ES_Multiday_Trend' } {'FBTP_Intraday_Bias' } {'FBTP_Multiday_Trend' } {'FC_Multiday_Trend' } {'FDAX_Intraday_Bias' } {'FDAX_Intraday_Reversal'} {'FDAX_Intraday_Trend' } {'FDAX_Multiday_Bias' }
RankListUnique = unique(RankListFull, 'stable') % Unique Entries (Un-sorted)
RankListUnique = 90×1 cell array
{'AD_Multiday_Reversal' } {'BP_Multiday_Bias' } {'BP_Multiday_Reversal' } {'BP_Intraday_Reversal' } {'BP_Multiday_Trend' } {'CC_Multiday_Bias' } {'CL_Intraday_Bias' } {'CL_Intraday_Trend' } {'CL_Intraday_Reversal' } {'CL_Multiday_Trend' } {'CL_Multiday_Reversal' } {'C_Multiday_Trend' } {'EC_Intraday_Reversal' } {'EC_Multiday_Reversal' } {'EC_Intraday_Bias' } {'EC_Intraday_Trend' } {'EC_Multiday_Trend' } {'ES_Multiday_Reversal' } {'ES_Intraday_Reversal' } {'ES_Multiday_Bias' } {'ES_Intraday_Trend' } {'ES_Multiday_Trend' } {'ES_Intraday_Bias' } {'FBTP_Multiday_Trend' } {'FBTP_Intraday_Bias' } {'FC_Multiday_Trend' } {'FDAX_Intraday_Bias' } {'FDAX_Intraday_Trend' } {'FDAX_Intraday_Reversal'} {'FDAX_Multiday_Reversal'}
.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by