Effacer les filtres
Effacer les filtres

Heatmap: Vector of x values ​​contains duplicate values

33 vues (au cours des 30 derniers jours)
Torsten K
Torsten K le 25 Sep 2020
Commenté : Ameer Hamza le 25 Sep 2020
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

Réponse acceptée

Ameer Hamza
Ameer Hamza le 25 Sep 2020
Modifié(e) : Ameer Hamza le 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"
  2 commentaires
Torsten K
Torsten K le 25 Sep 2020
Perfect answer! Thanks a lot, Ameer!
Ameer Hamza
Ameer Hamza le 25 Sep 2020
I am glad to be of help! :)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Colormaps dans Help Center et File Exchange

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by