필터 지우기
필터 지우기

Heatmap: Vector of x values ​​contains duplicate values

조회 수: 33 (최근 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 CenterFile Exchange에서 Colormaps에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by