How does this code work? Decreasing error bar width using xdata

조회 수: 2 (최근 30일)
Gaibo Zhang
Gaibo Zhang 2016년 6월 24일
댓글: yogesh jain 2016년 6월 25일
So I was looking online for a way to decrease error bar width on R2014a and found some code that works perfectly by a David Szotten. However, I still don't understand xdata and how it was used here to achieve what we wanted. Can someone explain this line by line? Here it is reproduced:
function removeErrorBarEnds(hErrBar)
%removeErrorBarEnds
% removeErrorBarEnds(hErrBar) removes the lines above/below errorbars
% generated by the MATLAB function hErrBar = errorbar()
% david szotten
% use length of xdata to find the right handle
% there may be an easier way to do this
dataLen = length( get(hErrBar, 'xdata') );
% objects to try, one of this is the errorbars
candidateList = findall(hErrBar);
for candidate = candidateList(:)'
candLen = length( get(candidate, 'xdata') );
% found it
if candLen == 9 * dataLen
xOrg = get(candidate, 'xdata');
yOrg = get(candidate, 'ydata');
% we only want the first 3 out or every 9
valuesToExtract = find( kron( ones(1,dataLen), [ones(1,3) zeros(1,6)] ) );
xNew = xOrg(valuesToExtract);
yNew = yOrg(valuesToExtract);
set(candidate, 'xdata', xNew);
set(candidate, 'ydata', yNew);
end
end
  댓글 수: 1
yogesh jain
yogesh jain 2016년 6월 25일
The coding part is not tough but it seems that it is following any particular algorithm which is a bit tough.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Errorbars에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by