Heatmap: Vector of x values ​​contains duplicate values

45 views (last 30 days)
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

Accepted Answer

Ameer Hamza
Ameer Hamza on 25 Sep 2020
Edited: Ameer Hamza on 25 Sep 2020
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"

More Answers (0)

Categories

Find more on Colormaps in Help Center and File Exchange

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!