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
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
plot(ii,Vplot)
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
Vplot(ii)=V?
RE: trouble plotting nested loop results
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
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
RE: trouble plotting nested loop results
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
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?