Heatmap: Vector of x values ​​contains duplicate values

45 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Ameer Hamza
Ameer Hamza il 25 Set 2020
Modificato: Ameer Hamza il 25 Set 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"

Più risposte (0)

Categorie

Scopri di più su Colormaps in Help Center e File Exchange

Prodotti


Release

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by