Keeping Error Bars while Subplotting

6 Ansichten (letzte 30 Tage)
Yugarshi Mondal
Yugarshi Mondal am 27 Jul. 2019
Beantwortet: Yugarshi Mondal am 27 Jul. 2019
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.

Antworten (1)

Yugarshi Mondal
Yugarshi Mondal am 27 Jul. 2019
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');

Kategorien

Mehr zu Errorbars finden Sie in Help Center und File Exchange

Produkte


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by