Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

trouble plotting nested loop results

Status
Not open for further replies.

matlabman

Civil/Environmental
Apr 30, 2010
3
hi,
I am relatively new to matlab and have created a code for a problem using loops however I want to display the results of each iteration as a graph. I can plot as dots by using hold on/hold off - effectively just overlaying numerous single point graphs. does anyone know how I can get the results to display as a continuos line graph.
the code I have is:

%Inputs
Hi=8;
Qin=xlsread('data')
A=223453;
Hd=18;
Qout=5.26*24*60*60/1000

%Calcs
V=Hi*A/1000
Vmax=A*Hd/1000


%reset ii (index value)
if V>=0.9*Vmax
ii=1
else ii=0
end

while ii<155
if V<0.9*Vmax
ii=ii+1;
end

hold on
plot (ii,V)



if V>=0.9*Vmax

while V>0.7*Vmax && ii
ii=ii+1;


if V+Qin(ii)-Qout*3 > Vmax
V=Vmax

else V=V+Qin(ii)-Qout*3

end

end


elseif V>=0.3*Vmax
V=V+Qin(ii)-Qout

if V>=Vmax
V=Vmax
end


else
V=V+Qin(ii)
while V<0.5*Vmax && ii<155
ii=ii+1;

if Qin(ii)> (Vmax-V)
V=Vmax
else V=V+Qin(ii)
end

end
if V<0.9*Vmax

end
end




end
hold off
 
Replies continue below

Recommended for you

thanks for trying to help, I tried inserting this command into my code but still can't get it to display a graph. where abouts in the code should I have inserted the
Vplot(ii)=V?
 
where you had the other plot line. You might need pause(0.1) as well, and you can get rid of the hold on statements.

Needless to say, since I can't run the code I can't check it.



Cheers

Greg Locock


New here? Try reading these, they might help FAQ731-376
 
Possibly connected...

I often want to animate a 2D plot. It can be done nicely using handles.

p=plot(x,y);
set (p,'erasemode','xor');

% Animation loop
for %some loop counter
set(p,'ydata',somNewYvalue);
end

On the same subject, the Matlab "drawnow" function can be used to force a plot update.






- Steve
 
Ah, much more elegant than pause(0.1)

Incidentally have you found a way of forcing octave to print to the terminal during a run? I'm using 3.0.1 and it tends not to print out intermediate results until the run has finished.





Cheers

Greg Locock


New here? Try reading these, they might help FAQ731-376
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor