MATLAB Maximizing Plot Clarity: Adding Formatting Without Clearing in Matlab

  • Thread starter Thread starter freezer
  • Start date Start date
  • Tags Tags
    Plot
AI Thread Summary
The discussion centers on a MATLAB plotting issue where the user successfully creates a plot within a for loop but encounters problems when formatting the title and axes afterward, which clears the plot. The user notes that adding a legend does not clear the plot, indicating that the issue lies specifically with the axis and title formatting commands. Initially, the user attempted to use "hold all" to retain the plot but found it ineffective. Ultimately, the problem was resolved when the user discovered that the axis scale was incorrectly set, causing the plot to appear shifted off-screen. This realization highlights the importance of ensuring correct axis limits when plotting in MATLAB.
freezer
Messages
75
Reaction score
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
Sorry, never mind... had my axis scale off and it was just shifted off plot..
 

Similar threads

Replies
8
Views
2K
Replies
5
Views
2K
Replies
1
Views
3K
Replies
1
Views
375
Replies
1
Views
3K
Replies
2
Views
8K
Replies
1
Views
2K
Replies
6
Views
3K
Back
Top