Keeping Error Bars while Subplotting

9 ビュー (過去 30 日間)
Yugarshi Mondal
Yugarshi Mondal 2019 年 7 月 27 日
回答済み: Yugarshi Mondal 2019 年 7 月 27 日
I've written the following code which takes plotted data and dumps it into a subplot. I want to annotate each of the subplots with an error bar and some text. However, when i go to draw the error bars, the actual figure gets erased! (Notice even the x & y labeling gets erased)
What am I doing wrong? Here's my code:
figs = [2 4 3 6];
for j=1:4
endX = 200;
newh = copyobj(allchild(get(figs(j),'CurrentAxes')),h(j));
ylim(h(j), [0 .5]); ylabel(h(j),'S');
xlim(h(j), [0 endX]); xlabel(h(j), 'Time (ms)');
dataObjs = findobj(h(j),'-property','YData');
pks = findpeaks(dataObjs.YData); trs = findpeaks(-1*dataObjs.YData)*-1; ampSS = pks(end) - trs(end);
bracket = errorbar(h(j),endX,trs(end) + ampSS/2, ampSS/2,'vertical','linewidth',1.5);
txt = text(h(j),endX,trs(end) - .02, strcat('Amp = ',num2str(ampSS)), 'horizontalalignment','center','verticalalignment','top','fontsize',8);
end
Note that commenting the line with "bracket = ..." results in the orginal plot with annotations. So its a problem with errorbar.

回答 (1 件)

Yugarshi Mondal
Yugarshi Mondal 2019 年 7 月 27 日
Adding the following code before calling errorbar solves the this. I think the error bar must be drawn using plot, and so holding as if you were plotting another line on the same subplot fixes this.
set(h(j),'NextPlot','add');

カテゴリ

Help Center および File ExchangeErrorbars についてさらに検索

タグ

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by