problem with cell array e unique

4 vues (au cours des 30 derniers jours)
Luca Re
Luca Re le 30 Août 2023
>> 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.

Réponse acceptée

Star Strider
Star Strider le 30 Août 2023
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'}
.

Plus de réponses (0)

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by