MATLAB: Plotting all iterations on a single graph?

In summary, the code is using 'hold on' to plot multiple iterations of r vs. Total_thrust on a single graph. However, it appears that the code may have extra 'end' statements and may need to iterate more than once for the plot to be useful.
  • #1
plexus0208
49
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
  • #2
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:

Related to MATLAB: Plotting all iterations on a single graph?

1. What is MATLAB?

MATLAB is a high-level programming language and interactive environment used by scientists and engineers for data analysis, visualization, and numerical computation.

2. How can I plot all iterations on a single graph using MATLAB?

To plot all iterations on a single graph in MATLAB, you can use the "hold on" command after each iteration to keep the previous plot on the graph and add the new plot on top of it. Alternatively, you can use the "plot" command to plot all the data points at once.

3. Can I customize the appearance of each iteration on the graph?

Yes, you can customize the appearance of each iteration on the graph by using different colors, markers, and line styles for each plot. This can be done by specifying the desired properties in the "plot" command.

4. How can I save the graph with all iterations for future reference?

To save the graph with all iterations, you can use the "saveas" function in MATLAB. This will allow you to save the graph as an image file such as PNG, JPEG, or TIFF, which can be easily accessed and viewed in the future.

5. Is it possible to add a legend to the graph for better understanding?

Yes, you can add a legend to the graph in MATLAB by using the "legend" command. This will allow you to label each iteration on the graph, making it easier to understand and interpret the data.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
850
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
12
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
14
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
813
Back
Top