フィルターのクリア

Error using string concatenation as input to ordinal( ) function

2 ビュー (過去 30 日間)
Robyn Seery
Robyn Seery 2021 年 4 月 12 日
コメント済み: Robyn Seery 2021 年 4 月 12 日
Hi, I am trying to create dynamic legend titles, based on numeric input ranges (RSRP signal levels). Given input sorted_RSRP, I am adding a category column, to specify the signal ranges for plotting colour-coded map data.
To do this, I have attempted to combine string values in the ordinal( ) function so I can display the ranges (that would change for different data sets) in the legend. I get the following error:
Error using categorical (line 391)
CATEGORYNAMES must be a string array or cell array of character vectors containing non-blank category names.
Error in ordinal (line 148)
b = b@categorical(a,args{:},'Ordinal',true);
See code below:
% five data categories
p = 0:0.2:1;
breaks = quantile(rsrp,p)
% string concatenation to show numeric range values
a = num2str(breaks(1)) + " to " + num2str(breaks(2))
b = num2str(breaks(2)) + " to " + num2str(breaks(3))
c = num2str(breaks(3)) + " to " + num2str(breaks(4))
d = num2str(breaks(4)) + " to " + num2str(breaks(5))
e = "> " + num2str(breaks(5))
% categorise RSRP
catRSRP = ordinal(rsrp, {a,b,c,d,e}, [], breaks);
% I have also tried this, inputting string concatenation directly
% catRSRP = ordinal(data_sorted.RSRP, {num2str(breaks(1)) + " to " + num2str(breaks(2)), ...
% num2str(breaks(2)) + " to " + num2str(breaks(3)), ...
% num2str(breaks(3)) + " to " + num2str(breaks(4)), ...
% num2str(breaks(4)) + " to " + num2str(breaks(5)), ...
% "> " + num2str(breaks(5))}, [], breaks);
Not entirely sure what the error I am getting means, none of the a, b, c, d, e string variables are empty.
Any help would be greatly appreciated!
  2 件のコメント
the cyclist
the cyclist 2021 年 4 月 12 日
It would be helpful if you uploaded the data variable in a MAT file, so that we can see exactly what you are.
Robyn Seery
Robyn Seery 2021 年 4 月 12 日
@the cyclist Apologies, I completely forgot! I have edited the question and code, adding in the data I am using.

サインインしてコメントする。

採用された回答

Cris LaPierre
Cris LaPierre 2021 年 4 月 12 日
編集済み: Cris LaPierre 2021 年 4 月 12 日
There is a warning at the top of the documentation page for ordinal
  • The nominal and ordinal array data types are not recommended. To represent ordered and unordered discrete, nonnumeric data, use the Categorical Arrays data type instead.
I think what you want to use is discretize to assign categories to the values based on what bin they would fall into. Use the syntax
load rsrp.mat
% five data categories
p = 0:0.2:1;
breaks = quantile(rsrp,p);
% string concatenation to show numeric range values
a = breaks(1) + " to " + breaks(2);
b = breaks(2) + " to " + breaks(3);
c = breaks(3) + " to " + breaks(4);
d = breaks(4) + " to " + breaks(5);
e = "> " + breaks(5);
% categorise RSRP
catRSRP = discretize(rsrp,breaks,'categorical',[a,b,c,d,e]);
catT = table(rsrp,catRSRP)
catT = 1153×2 table
rsrp catRSRP ____ ____________ -115 -115 to -103 -114 -115 to -103 -113 -115 to -103 -113 -115 to -103 -113 -115 to -103 -113 -115 to -103 -112 -115 to -103 -112 -115 to -103 -111 -115 to -103 -111 -115 to -103 -111 -115 to -103 -111 -115 to -103 -111 -115 to -103 -111 -115 to -103 -111 -115 to -103 -110 -115 to -103
  1 件のコメント
Robyn Seery
Robyn Seery 2021 年 4 月 12 日
Thank you very much, works just as I needed it to! Really appreciate your help.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Identification についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by