MATLAB: Plotting all iterations on a single graph?

  • Context: MATLAB 
  • Thread starter Thread starter plexus0208
  • Start date Start date
  • Tags Tags
    Graph Matlab Plotting
Click For Summary
SUMMARY

The discussion focuses on plotting multiple iterations of thrust data in MATLAB using the 'hold on;' command. The user is experiencing issues where only the last iteration is displayed on the graph. The solution involves ensuring that the plotting command is executed within a loop that iterates through all data points, as demonstrated in the provided sine plot example. Additionally, the user is advised to check for any unnecessary 'end' statements that may disrupt the flow of the code.

PREREQUISITES
  • Familiarity with MATLAB programming
  • Understanding of plotting functions in MATLAB
  • Knowledge of control structures (loops) in MATLAB
  • Basic concepts of thrust calculations in engineering applications
NEXT STEPS
  • Review MATLAB plotting functions and their usage
  • Learn about MATLAB control structures, specifically loops
  • Explore MATLAB's 'hold on;' functionality in detail
  • Investigate best practices for managing plot data in MATLAB
USEFUL FOR

Engineers, data analysts, and MATLAB users who need to visualize multiple data iterations effectively in their projects.

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 ·
Replies
8
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 9 ·
Replies
9
Views
5K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 12 ·
Replies
12
Views
7K
  • · Replies 1 ·
Replies
1
Views
3K