필터 지우기
필터 지우기

Plotyy and error bars

조회 수: 6 (최근 30일)
Clement Wong
Clement Wong 2011년 8월 3일
I'd like to do a plotyy function, and I have confidence intervals for each point of my data. I can't seem to figure out a way to do both of these at once. My x data is stored in an array RC, and the two y data are in arrays L and D. The confidence intervals are in ciL and ciD, and are not necessarily symmetric. Is there an easy way to add these as error bars to my plot?
  댓글 수: 2
Jan
Jan 2011년 8월 3일
If you post the code you have currently, it would be easier to insert the changes.
Clement Wong
Clement Wong 2011년 8월 3일
The code looks something like this:
x = 1;
for rc = 1000:1000:10000
[beta,r,j,covb,mse] = nlfin(parameters including rc);
ci = nlparci(beta,r,'covar',covb);
L(x) = beta(2);
D(x) = beta(3);
ciL(x,:) = ci(2,:);
ciD(x,:) = ci(3,:);
x = x+1;
end
L,D,ciL,ciD are all preallocated for speed. But the idea is that now, I have the confidence intervals for all 10 data points as I sweep rc. RC goes from 1,000 to 10,000 in 1,000 step size. I'm plotting the values for L and D against RC using plotyy(RC,L,RC,D,semilogx).
ciL and ciD contain the confidence intervals for each point, in order. That is, if L(1) is 5, then ciL(1) could be something like [3 8]. I hope this makes sense.

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

채택된 답변

Patrick Kalita
Patrick Kalita 2011년 8월 3일
When customizing graphs made with plotyy, it is usually useful to store axes handles that it provides as its return value. With those axes handles you can (1) turn hold mode on for each one and (2) add errorbars to each.
Here's an example:
% Make up some data to plot
x = 1:5;
y1 = rand(1,5);
y2 = rand(1,5) + 100;
L1 = 0.01 * ones(1,5);
U1 = 0.02 * ones(1,5);
L2 = 0.03 * ones(1,5);
U2 = 0.04 * ones(1,5);
% Store the axes handles produced by PLOTYY
ax = plotyy(x, y1, x, y2);
% Use HOLD and ERRORBAR, passing axes handles to the functions.
hold(ax(1), 'on');
errorbar(ax(1), x, y1, L1, U1);
hold(ax(2), 'on');
errorbar(ax(2), x, y2, L2, U2);
  댓글 수: 2
Clement Wong
Clement Wong 2011년 8월 3일
I have one question. For the errorbars, do I have to convert my confidence interval (ci) into amount below and amount above the given value? That is, say my data point is 5, and my ci is [3 9]. Then would I need to make L = 2 (5 - 3 = 2), and U = 4 (9 - 5 = 4)? That's how it seems to work. Is there any way to just input a range for the errobars? I want to be able to input the code errorbar(x,y,ci(1,:),ci(2,:)), because the nlparci method that I'm using to create my ci's give them in that form. It's not much trouble to change it to the other form, but it would be easier this way, if there's a way to do it.
Thanks again!
Patrick Kalita
Patrick Kalita 2011년 8월 8일
No, that's not the way ERRORBAR wants its lower and upper bounds. I guess you'll have to convert.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Two y-axis에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by