Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Matlab Code: 2D Plot Example. Run the following example of a sine wave plot: % 2D sine wave plot % Graphing two or more lines

Matlab Code:

image text in transcribed

image text in transcribed

2D Plot Example. Run the following example of a sine wave plot: % 2D sine wave plot % Graphing two or more lines in the same plot (using hold all) % File: plot102.m clc, clear, clf n -20; x linspace(0,4*pi,200); % sets number of waves to plot % 200 data points evenly spaced from 0 to 4*pi hold all for i-1:n % overlay multiple plots on the same graph % loop through n times % define nth sine wave % plot to screen y-i*sin(x+2%*pi); plot(x,y) end % Label axes xlabel('x') ylabel( Wave height') % we want to label the graph with the number of waves % Because the title command only accepts strings, we "print" the value n % into a string (called str) and then concatenate it to the string % 'Sine Waves' using the square brackets. str sprintf('%i', n); title([str'Sine Waves'], 'FontSize',14) % Set axis limits for plot xlim([0 4*pi]) ylim([-(n+2) (n+2))); % the max wave amplitude-n, so scale the plot in % x axis just goes from 0 to 4 pi % the y direction from-(n+2) to +(n+2). The offset % of 2 just gives the curves a little breathing room hold off % releases the plot (so in a new run it starts a new plot) Some more code explanation The hold all command prevents Matlab from overwriting previous plots. Once hold all is called successive plot function will simply overlay lines on top of each other. The plot ( function was used in a for loop and let all 20 plots pile up. Because there are so many curves we abandon keeping track of them with a legend This example also uses the sprintf ()function combined with the title( function to automatically display the number of sine waves in the title without having to change it by hand each time. Answer the following questions 2D Plot Example. Run the following example of a sine wave plot: % 2D sine wave plot % Graphing two or more lines in the same plot (using hold all) % File: plot102.m clc, clear, clf n -20; x linspace(0,4*pi,200); % sets number of waves to plot % 200 data points evenly spaced from 0 to 4*pi hold all for i-1:n % overlay multiple plots on the same graph % loop through n times % define nth sine wave % plot to screen y-i*sin(x+2%*pi); plot(x,y) end % Label axes xlabel('x') ylabel( Wave height') % we want to label the graph with the number of waves % Because the title command only accepts strings, we "print" the value n % into a string (called str) and then concatenate it to the string % 'Sine Waves' using the square brackets. str sprintf('%i', n); title([str'Sine Waves'], 'FontSize',14) % Set axis limits for plot xlim([0 4*pi]) ylim([-(n+2) (n+2))); % the max wave amplitude-n, so scale the plot in % x axis just goes from 0 to 4 pi % the y direction from-(n+2) to +(n+2). The offset % of 2 just gives the curves a little breathing room hold off % releases the plot (so in a new run it starts a new plot) Some more code explanation The hold all command prevents Matlab from overwriting previous plots. Once hold all is called successive plot function will simply overlay lines on top of each other. The plot ( function was used in a for loop and let all 20 plots pile up. Because there are so many curves we abandon keeping track of them with a legend This example also uses the sprintf ()function combined with the title( function to automatically display the number of sine waves in the title without having to change it by hand each time. Answer the following questions

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Expert Oracle9i Database Administration

Authors: Sam R. Alapati

1st Edition

1590590228, 978-1590590225

More Books

Students also viewed these Databases questions