Maximizing Plot Clarity: Adding Formatting Without Clearing in Matlab

  • MATLAB
  • Thread starter freezer
  • Start date
  • Tags
    Plot
In summary, the conversation discusses creating a plot in a for loop in MATLAB and encountering issues with formatting the title and axis without clearing the plot. The solution involves using the "hold on" command and commenting out certain code to add the legend without clearing the plot. The issue was found to be caused by an incorrect axis scale.
  • #1
freezer
76
0
I am creating a plot in a for loop adding each iteration to the plot in matlab. This part works fine but after the for loop, i am trying to format the title and axis and that is clearing the plot. I can add the legend without it clearing. I also tried hold all but that did not work either. Any tips to get the formatting addition to not clear the plot?

this is the plot that is in the for loop:

plot(W,M,'color',[1-ii/10 ii/10 1]); hold on Then after the for loop:
Code:
axis([0 2500 0 1.1]) 
title('BPFs') 
xlabel('Frequency (Hz)'); 
ylabel('Magnitude'); grid on

I can add the legend without it clearing if i comment out the code above.

Code:
legend(['F_c= ',int2str(fb(1)),' Hz'],['F_c= ',int2str(fb(2)),' Hz'],... % Creates the legend of the plot.
['F_c= ',int2str(fb(3)),' Hz'],['F_c= ',int2str(fb(4)),' Hz'],...
['F_c= ',int2str(fb(5)),' Hz'],['F_c= ',int2str(fb(6)),' Hz'],...
['F_c= ',int2str(fb(7)),' Hz'],['F_c= ',int2str(fb(8)),' Hz']);
 
Physics news on Phys.org
  • #2
Sorry, never mind... had my axis scale off and it was just shifted off plot..
 

1. How can I add formatting to my plot without clearing it in Matlab?

To add formatting without clearing your plot, you can use the "hold on" command. This will allow you to make multiple changes to your plot without overwriting the previous changes.

2. Can I add multiple formatting changes to my plot without clearing it?

Yes, by using the "hold on" command, you can make as many formatting changes as you want without clearing your plot in Matlab.

3. What is the benefit of using the "hold on" command?

The "hold on" command allows you to make multiple changes to your plot without clearing it, saving you time and effort in re-plotting the data.

4. How do I turn off the "hold on" command in Matlab?

To turn off the "hold on" command, you can use the "hold off" command. This will return your plot to its default setting, where each new plot overwrites the previous one.

5. Can I use the "hold on" command in conjunction with other formatting commands in Matlab?

Yes, the "hold on" command can be used with other formatting commands in Matlab. This allows for more flexibility in customizing your plot without clearing it.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
8K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
3K
Back
Top