plotting data in a loop

I'm trying to plot a bar graph that shows a value that's fixed at the beginning of the loop (XSSUPDEM) and in the same graph show how another series is growing (RAMPINGGEN(1)).
while XSSUPDEM + RAMPINGGEN(1)<0
OFFSIZE=SUPSTACK(ROWVALSUP,5);
RAMPRATE=SUPSTACK(ROWVALSUP,8);
MINRAMP=OFFSIZE/RAMPRATE;
if MINRAMP>10 && RAMPRATE*10 < abs(XSSUPDEM + RAMPINGGEN(1))
NUMINTERVALS=floor(MINRAMP/10);
for j=1:NUMINTERVALS;
RAMPINGGEN(j)=RAMPINGGEN(j)+RAMPRATE*10;
end
RAMPINGGEN(j+1)=RAMPINGGEN(j+1)+(OFFSIZE-((NUMINTERVALS)*(RAMPRATE*10)));
elseif MINRAMP>10 && RAMPRATE*10 > abs(XSSUPDEM+ RAMPINGGEN(1))
RAMPINGGEN(1)=RAMPINGGEN(1)+abs(XSSUPDEM + RAMPINGGEN(1));
elseif MINRAMP<10 && OFFSIZE < abs(XSSUPDEM + RAMPINGGEN(1))
RAMPINGGEN(1)=RAMPINGGEN(1)+OFFSIZE;
elseif MINRAMP<10 && OFFSIZE > abs(XSSUPDEM + RAMPINGGEN(1))
RAMPINGGEN(1)=RAMPINGGEN(1)+abs(XSSUPDEM + RAMPINGGEN(1));
bar([abs(XSSUPDEM) abs(RAMPINGGEN(1))], 'stacked');
end

답변 (1개)

Oleg Komarov
Oleg Komarov 2011년 7월 23일

0 개 추천

Is this what you're trying to achieve?
A = rand(10,1);
B = rand(10,1);
hh = bar([A B], 'stacked');
for n = 1:10
set(hh(2),'Ydata', get(hh(2),'Ydata') + rand(1,10));
pause(.2)
end

댓글 수: 5

Amy
Amy 2011년 7월 23일
I think that's pretty close except B is calculated inside a while loop while A is determined outside the loop..
Oleg Komarov
Oleg Komarov 2011년 7월 23일
It doesn't matter if it's a for or while.
To be able to "grow" B, you have to call bar outside the loop and then set B's Ydata inside the loop otherwise it will replot the bar at each iteration.
Amy
Amy 2011년 7월 23일
I get an error because XSSUPDEM which is calculated outside the loop is a single data point while RAMPINGGEN is an array..Any hints? I'm stumped
Amy
Amy 2011년 7월 23일
Attempted to access hh(2); index out of
bounds because numel(hh)=1.
Error in ==> OverdispatchV2 at 206
set(hh(2),'YData', get(hh(2),'YData'));
Oleg Komarov
Oleg Komarov 2011년 7월 23일
What do you get with size([abs(XSSUPDEM) abs(RAMPINGGEN(1))])?

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

카테고리

도움말 센터File Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

질문:

Amy
2011년 7월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by