MATLAB graphics drawing-image overlap and linspace command

Image overlay and linspace commands

If we draw an image of a function and then decide to draw another image on the same graph, we can achieve this goal by telling MATLABhold on:
In the following example, we will draw sin (x) and cos (x ) On the same picture.
First let's learn the linspace command:

x = linspace(a,b)

MATLAB will take 100 points (vectors) evenly distributed from a to
b.If written as:

x = linspace(a,b,n)

Then MATLAB will take n points distributed evenly between a and b. Then we use this tool to draw cos (x) and sin (x) images, first let us take 100 points evenly between 0 ~ 2 * pi:

x = linspace(0,2*pi);

Then we draw cos (x):

plot(x,cos(x))

As shown: Cos (x) image drawn after using linspace command
If we enter:

plot(x,sin(x))

MATLAB will wash away the previous output, and the current graphics window becomes the following:
We entered the plot (x, sin (x)) command and washed out the previously drawn image
At this moment, it should be noted that
although we define the value range of x to be between 0 and 2 * pi, the graphics ratio calculated by MATLAB is calculated by the function The image is a bit wider, we can use the axis () command to adjust when calling plot (x, sin (x)):

>> plot(x,sin(x)),axis([0 2*pi -1 1])

Image: We corrected the image using the axis command
Back to our previous question, we want to draw sin (x) and cos (x) two images on an image, which can be done by the following command:

>> x = linspace(0,2*pi);
>> y1 = sin(x);
>> y2 = cos(x);
>> plot(x,y1),axis([0 2*pi -1 1])
>> hold on
>> plot(x,y2),axis([0 2*pi -1 1])

image:
Show two curves on the same image

Published 84 original articles · won 18 · views 5805

Guess you like

Origin blog.csdn.net/qq_44486550/article/details/105246834