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.
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 中查找有关 Interactive Control and Callbacks 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!