matlab 2015 bug - x position of bars in bar plot
조회 수: 3 (최근 30일)
이전 댓글 표시
hbar = bar( [1 2 ; 3 4])
Since Matlab 2015 , I am unable to get or infer the x position of each bar.
hbar(1).XData
merely gives
[1 2]
which is false (the bare are slightly offset from 1 and 2)
Other Matlab Answers suggest using
hbar(1).xOffset
However, this attribute is undocumented and hidden from the user, making it risky and unorthodox. Further, while "hbar(1).xOffset" returns a non-zero number when executed in the command window, it produces "0" within any script.
댓글 수: 0
답변 (1개)
Star Strider
2015년 9월 18일
I can’t reproduce the behaviour with XOffset that you’re seeing.
This works:
figure(1)
hbar = bar( [1 2 ; 3 4]);
xd = get(hbar,'XData');
yd = get(hbar,'YData');
ofst = get(hbar,'XOffset');
hold on
for k1 = 1:length(ofst)
plot(xd{k1}+ofst{k1}, yd{k1}/2, 'r*')
end
hold off
The ‘new’ HG2 introduced in R2014b removed a significant amount of the functionality of the previous handle graphics versions. (We are doing what we can to recover it.) Meanwhile, I would not upgrade to Windows 10 if you have the option, since R2014a and previous versions (with the ‘old’ handle graphics) will work on Windows 8.1 and previous versions, but Windows 10 is only compatible with R2015a and later, with their restricted handle graphics functionality.
댓글 수: 2
Tobias Gerken
2019년 7월 25일
I have exactly the same problem using Matlab 2018b on Windows 10.
b = bar(data,'FaceColor','flat');
a1=[get(b,'XOffset')]
% or
a2 = [(b.XOffset)]
%
a1 and a2 return zeros. But, when directly copied into the command window I get the correct answer
[(b.XOffset)]
ans =
-0.2727 -0.0909 0.0909 0.2727
j patri
2019년 8월 9일
You need to force the figure to be drawn before (using "drawnow"). This force the value of XOffset to be updated!
참고 항목
카테고리
Help Center 및 File Exchange에서 Animation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!