×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • 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.

Students Click Here

trouble plotting nested loop results

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;
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

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.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login



News


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:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close