Heatmap: Vector of x values ​​contains duplicate values

44 ビュー (過去 30 日間)
Torsten K
Torsten K 2020 年 9 月 25 日
コメント済み: Ameer Hamza 2020 年 9 月 25 日
Hello everybody,
I would like to create a heatmap in which the X-Labels are repeated. The X-Label categories are the strings "L", "M", and "R". Tried to make the strings unique by adding spaces, but it didn't work:
figure
h = heatmap(randi(100,10,12), 'Colormap', jet);
h.YData = ["E10" "E9" "E8" "E7" "E6" "E5" "E4" "E3" "E2" "E1"];
h.XData = ["L" "M" "R"
strcat(" ","L") strcat(" ","M") strcat(" ","R")
strcat(" ","L"," ") strcat(" ","M"," ") strcat(" ","R"," ")
strcat(" ","L"," ") strcat(" ","M"," ") strcat(" ","R"," ")];
The error message "Vector of x values ​​contains duplicate values" appears. Strangely enough, Matlab sees the generated strings as unique:
str = ["L" "M" "R"
strcat(" ","L") strcat(" ","M") strcat(" ","R")
strcat(" ","L"," ") strcat(" ","M"," ") strcat(" ","R"," ")
strcat(" ","L"," ") strcat(" ","M"," ") strcat(" ","R"," ")];
unique(str)
ans =
1×12 string array
" L " " M " " R " " L" " L " " M" " M " " R" " R " "L" "M" "R"
Where is the mistake? Does anyone have a solution?
Best regards
Torsten

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 9 月 25 日
編集済み: Ameer Hamza 2020 年 9 月 25 日
Instead of XData and YData, change XDisplayLabels and YDisplayLabels.
h.YDisplayLabels = ["E10" "E9" "E8" "E7" "E6" "E5" "E4" "E3" "E2" "E1"];
h.XDisplayLabels = ["L" "M" "R"
strcat(" ","L") strcat(" ","M") strcat(" ","R")
strcat(" ","L"," ") strcat(" ","M"," ") strcat(" ","R"," ")
strcat(" ","L"," ") strcat(" ","M"," ") strcat(" ","R"," ")];
As a side note, I am not sure why are you using strcat here.
strcat(" ","L")
is equivalent to
" L"
  2 件のコメント
Torsten K
Torsten K 2020 年 9 月 25 日
Perfect answer! Thanks a lot, Ameer!
Ameer Hamza
Ameer Hamza 2020 年 9 月 25 日
I am glad to be of help! :)

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeColormaps についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by