MATLAB MATLAB: Plotting all iterations on a single graph?

AI Thread Summary
To plot all iterations of r versus Total_thrust on a single graph in MATLAB, ensure that the plotting occurs within the loop that generates the data. The use of 'hold on;' is correct, but the plot command should be inside the loop to capture each iteration's data. The current code structure suggests that the plot command is executed only once after the loop, which results in only the last iteration being displayed. Additionally, check for any unnecessary end statements that may disrupt the flow of the code. Properly structuring the loop and plot commands will allow for all iterations to be visualized effectively.
plexus0208
Messages
49
Reaction score
0
I want to plot r vs. Total_thrust for all iterations on a single graph. I'm using 'hold on;' but it is still only plotting the last iteration. Help?

-------------------MATLAB CODE----------------------------------
Thrust = (mdot19*c19 + mdot9*c9)/gc; %Note: This is for one engine

if(imag(Thrust) == 0 ),
Total_thrust(i) = Thrust*2; %in lbf
SFC(i) = (mdotf/Thrust)*3600; %in (lbm/hr)/lbf
r(i) = radius_inlet;
i = i+1;
end

radius_inlet = radius_inlet + .1;

end

Tt4 = Tt4 + 30;
plot(r,Total_thrust);
hold on;

end
 
Physics news on Phys.org
Unless there's some additional code that's not included here, you seem to have some superfluous end statements. If you go through the hold route, you generally want to make sure that the plot data iterates several times (otherwise, it's useless).

F'r instance:
Code:
%Sine plotter
t=0:0.01:2*pi;
hold on
for n=1:1:5
	plot(t, sin(n*t));
end
hold off;
 
Last edited:

Similar threads

Replies
8
Views
2K
Replies
2
Views
3K
Replies
4
Views
2K
Replies
1
Views
2K
Replies
3
Views
2K
Replies
9
Views
5K
Back
Top