Problem when print bar graph
조회 수: 1 (최근 30일)
이전 댓글 표시
Dear members
I have this problem. I want to print figure as I attached. But When I printed, it has problems. Could you help me solve this problem.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/283379/image.png)
measles = [38556 24472 14556 18060 19549 8122 28541 7880 3283 4135 7953 1884 38556 24472 14556 18060 19549 8122 28541 7880 3283 4135]';
mumps = [20178 23536 34561 37395 36072 32237 18597 9408 6005 6268 8963 13882 20178 23536 34561 37395 36072 32237 18597 9408 6005 6268]';
chickenPox = [37140 32169 37533 39103 33244 23269 16737 5411 3435 6052 12825 23332 37140 32169 37533 39103 33244 23269 16737 5411 3435 6052]';
xvector1 = [measles, mumps, chickenPox];
bar1 = bar(xvector1,xvector1,'Parent',axes1);
set(bar1(4),'Visible','off');
set(bar1(3),'DisplayName','Test','FaceColor',[1 0 0]);
set(bar1(2),'DisplayName','Validation','FaceColor',[0 0.8 0]);
set(bar1(1),'DisplayName','Training','FaceColor',[0 0 1]);
Error is: Error using bar.
XData cannot contain duplicate values.
댓글 수: 2
dpb
2020년 4월 10일
Printing has nothing to do with the error and the attached code didn't create that figure...
>> figure
>> hbar1 = bar(xvector1,xvector1);
Error using bar (line 170)
XData values must be unique.
>>
The error is that you tried to call bar with the same data vector xvector as the x-axis variable as the y-axis variable and there are
>> [numel(xvector1) numel(unique(xvector1))]
ans =
66 36
>>
and the values in the vector aren't unique so that can't work to draw more than one bar at the same x location that is what that would try to do.
Don't know specifically what you did intend, but the above simply is just wrong attempted use of bar
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Bar Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!