Keeping Error Bars while Subplotting

6 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Errorbars 的更多信息

标签

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by