Maximizing Plot Clarity: Adding Formatting Without Clearing in Matlab

  • Context: MATLAB 
  • Thread starter Thread starter freezer
  • Start date Start date
  • Tags Tags
    Plot
Click For Summary
SUMMARY

The discussion focuses on a common issue in MATLAB where formatting commands, such as setting axis limits and adding titles, inadvertently clear existing plots. The user successfully creates a plot within a for loop using the command plot(W,M,'color',[1-ii/10 ii/10 1]); hold on. However, attempts to format the plot afterward using axis, title, xlabel, and ylabel led to confusion, as the plot appeared cleared. The issue was resolved when the user identified that the axis scale was incorrectly set, causing the plot to be shifted off-screen.

PREREQUISITES
  • Familiarity with MATLAB plotting functions
  • Understanding of the hold on command in MATLAB
  • Knowledge of axis scaling in MATLAB
  • Basic experience with MATLAB for loops
NEXT STEPS
  • Research MATLAB's hold on and hold off commands for plot management
  • Explore MATLAB's axis manipulation functions, including axis and set
  • Learn about MATLAB's plotting properties and how to modify them without clearing plots
  • Investigate debugging techniques for visualizing data in MATLAB plots
USEFUL FOR

This discussion is beneficial for MATLAB users, data analysts, and engineers who are involved in creating and formatting plots without losing existing data visualizations.

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