×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Are you an
Engineering professional?
Join Eng-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

#### Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

# trouble plotting nested loop results

## trouble plotting nested loop results

(OP)
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;
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

### RE: trouble plotting nested loop results

(OP)
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?

### RE: trouble plotting nested loop results

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: Eng-Tips.com Forum Policies  http://eng-tips.com/market.cfm?

### RE: trouble plotting nested loop results

(OP)
awesome that worked thanks heaps

### RE: trouble plotting nested loop results

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

### RE: trouble plotting nested loop results

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: Eng-Tips.com Forum Policies  http://eng-tips.com/market.cfm?

#### Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

#### Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

#### Resources

Low-Volume Rapid Injection Molding With 3D Printed Molds
Learn methods and guidelines for using stereolithography (SLA) 3D printed molds in the injection molding process to lower costs and lead time. Discover how this hybrid manufacturing process enables on-demand mold fabrication to quickly produce small batches of thermoplastic parts. Download Now
Examine how the principles of DfAM upend many of the long-standing rules around manufacturability - allowing engineers and designers to place a partâ€™s function at the center of their design considerations. Download Now
Taking Control of Engineering Documents
This ebook covers tips for creating and managing workflows, security best practices and protection of intellectual property, Cloud vs. on-premise software solutions, CAD file management, compliance, and more. Download Now

Close Box

# Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!