天天看點

文學文享(8):Matlab繪圖學習之二維三維圖繪制及相關基礎操作

作者:LearningYard學苑
文學文享(8):Matlab繪圖學習之二維三維圖繪制及相關基礎操作

分享興趣,傳播快樂,增長見聞,留下美好。

親愛的您,這裡是LearningYard學苑!

今天小編為大家帶來Matlab繪圖學習分享。

歡迎您的通路!

Share interest, spread happiness, increase knowledge, and leave beautiful.

Dear, this is the LearingYard Academy!

Today, the editor brings the Matlab drawing learning and sharing.

Welcome to visit!

1 内容摘要(Content summary)

本文将分享小編學習Matlab繪圖的過程,本次學習的是Matlab基礎操作及二維圖和三維圖的基本繪制方法。

This article will share the editor's process of learning Matlab drawing. This time I will learn the basic operations of Matlab and the basic drawing methods of two-dimensional and three-dimensional graphics.

2 思維導圖(Mind mapping)

文學文享(8):Matlab繪圖學習之二維三維圖繪制及相關基礎操作

3 正文(Text)

3.1 Matlab入門學習(Matlab entry learning)

小編首先跟着教學,對Matlab的一些基礎入門操作進行了學習,為之後學習Matlab繪圖做了前期準備。在此期間學到了一些實用的功能和操作,将在下方進行展示。

The editor first followed the teaching and learned some basic introductory operations of Matlab, making preliminary preparations for learning Matlab drawing later. During this period, some useful functions and operations have been learned, which will be displayed below.

(1) Matlab可以進行矩陣的運算,分别給x和y指派一個矩陣,利用運算符号便可進行計算。

(1) Matlab can perform matrix operations, assign a matrix to x and y respectively, and use operation symbols to perform calculations.

文學文享(8):Matlab繪圖學習之二維三維圖繪制及相關基礎操作

在此學到的知識是:中括号中用分号隔開數字便可表示矩陣;每條指令後輸入分号可将指令的輸出結果不顯示在指令行視窗内;在進行矩陣乘法時,前面的變量後加個“.”便可進行矩陣内相對位置數字的乘法而不是傳統數學中的矩陣乘法。

The knowledge learned here is: The matrix can be represented by separating the numbers with a semicolon in the brackets. Entering a semicolon after each command can prevent the output of the command from being displayed in the command line window. When performing matrix multiplication, add a "." after the previous variable to perform multiplication of relative position numbers in the matrix instead of matrix multiplication in traditional mathematics.

(2) 可點選Matlab首頁菜單欄中的建立腳本選項來建構腳本,腳本可以将多條代碼封裝起來,點選運作後得出最終結果。

(2) You can click the New Script option in the menu bar of the Matlab home page to build a script. The script can encapsulate multiple codes, and the final result can be obtained after clicking Run.

文學文享(8):Matlab繪圖學習之二維三維圖繪制及相關基礎操作

在此學到的知識是:input()函數讓使用者輸入一個數指派給變量,提高了腳本互動性;fprintf()函數可輸出一串字元,使結果更美觀;\n表示換行;%f表示可帶小數的浮點數,%g表示實數。

The knowledge learned here is: The input() function allows the user to input a number and assign it to a variable, which improves the script interactivity. The fprintf() function can output a string of characters to make the result more beautiful. \n means newline. %f means a floating-point number that can take a decimal. %g means a real number.

(3) 使用if函數可進行判斷,進而跳過一些代碼的執行。

(3) The if function can be used to judge, thereby skipping the execution of some codes.

文學文享(8):Matlab繪圖學習之二維三維圖繪制及相關基礎操作

在此學到的知識是:elseif是if語句的延伸,用于處理兩個以上結果的判斷;判斷一個數字是否等于0,要使用兩個等于号;sqrt()表示根号;或者用“||”表示。

The knowledge learned here is: Elseif is an extension of the if statement, which is used to handle the judgment of more than two results. To judge whether a number is equal to 0, use two equal signs. sqrt() means the root sign. Or use "||" to indicate.

(4) while函數表示循環,在條件成立的情況下循環執行一定的代碼。

(4) The while function represents a loop, and executes a certain code in a loop when the condition is true.

文學文享(8):Matlab繪圖學習之二維三維圖繪制及相關基礎操作

在此學到的知識是:若開頭不給變量重新指派,那麼重複運作數字會越加越大;disp()同樣為輸出語句,可輸出帶換行的值;不等于用“~=”表示;mod()用于取兩數相除的商。

The knowledge learned here is: If the variable is not reassigned at the beginning, then the number will become larger and larger after repeated operations. disp() is also an output statement, which can output values with newlines. Not equal to use "~=" to express. mod() is used to take the quotient of dividing two numbers.

(5) for函數也用于表示循環。

(5) The for function is also used to represent loops.

文學文享(8):Matlab繪圖學習之二維三維圖繪制及相關基礎操作

在此學到的知識是:在“i=2:1:8”中,冒号的作用是使初始為2的i,每次加1,最終加到8,兩個冒号中間的值稱為步長。

The knowledge learned here is: In "i=2:1:8", the role of the colon is to make i, which is initially 2, increase by 1 each time, and finally add to 8. The value between the two colons is called the step size.

(6) function是Matlab内的自建函數,可以建立具有某種特定功能的函數,然後在其他函數中友善地調用。下面是自建函數及套用的過程,最終輸出1-1000内所有質數。

(6) Function is a self-built function in Matlab, you can create a function with a specific function, and then call it conveniently in other functions. The following is the self-built function and the process of applying it, and finally output all prime numbers within 1-1000.

文學文享(8):Matlab繪圖學習之二維三維圖繪制及相關基礎操作
文學文享(8):Matlab繪圖學習之二維三維圖繪制及相關基礎操作
文學文享(8):Matlab繪圖學習之二維三維圖繪制及相關基礎操作

在此學到的知識是:使用%可以友善地為函數的每個步驟進行标記,以免忘了是什麼意思。

The lesson learned here is that using % is a convenient way to label each step of a function so you don't forget what it means.

3.2 Matlab繪圖學習(Matlab drawing learning)

(1) plot()函數是用于繪制線圖的函數,最簡單的形式為plot(x,y),會将(x,y)看作坐标點繪制到圖上。

(1) The plot() function is a function used to draw a line graph. The simplest form is plot(x,y), which will treat (x,y) as a coordinate point and draw it on the graph.

文學文享(8):Matlab繪圖學習之二維三維圖繪制及相關基礎操作

繪圖時将x的步長設為一個較小的數,可使圖像更加平滑。

Setting the x step size to a small number when plotting can make the image smoother.

文學文享(8):Matlab繪圖學習之二維三維圖繪制及相關基礎操作
文學文享(8):Matlab繪圖學習之二維三維圖繪制及相關基礎操作

plot()函數中用單引号标記部分表示圖像的格式,-表示實線,o表示關鍵點用o标記,green表示綠色,顔色也可用單個字母表示,如k表示黑色。hold on的加入使得一張圖中可繪制多條曲線,axis equal可使x和y軸的機關長度相同。

The part marked with single quotes in the plot() function indicates the format of the image, - indicates a solid line, o indicates that key points are marked with o, green indicates green, and the color can also be expressed by a single letter, such as k indicates black. The addition of hold on allows multiple curves to be drawn in one graph, and axis equal makes the unit lengths of the x and y axes the same.

文學文享(8):Matlab繪圖學習之二維三維圖繪制及相關基礎操作

plot3()函數表示繪制三維圖像,在确定了二維圖像關鍵點數量後,需在z軸确定相同數量的關鍵點。

The plot3() function means to draw a three-dimensional image. After determining the number of key points of the two-dimensional image, it is necessary to determine the same number of key points on the z-axis.

文學文享(8):Matlab繪圖學習之二維三維圖繪制及相關基礎操作

為圖像添加标題使用title()函數,為坐标軸添加标簽分别使用xlabel()和ylabel()。

Add a title to the image using the title() function, and add labels to the axes using xlabel() and ylabel() respectively.

文學文享(8):Matlab繪圖學習之二維三維圖繪制及相關基礎操作

使用subplot()函數可将多幅圖畫在同一個視窗内的不同位置,函數内的三個數字分别代表将視窗分成幾行幾列及将圖檔畫在哪個位置。

Use the subplot() function to draw multiple pictures at different positions in the same window. The three numbers in the function represent how many rows and columns the window will be divided into and where the pictures will be drawn.

文學文享(8):Matlab繪圖學習之二維三維圖繪制及相關基礎操作

(2) surf()函數用于畫三維圖像中的一個面,利用meshgrid()函數找到平面内所有點後,即可繪制出一個曲面圖像。

(2) The surf() function is used to draw a surface in a three-dimensional image. After finding all the points in the plane using the meshgrid() function, a surface image can be drawn.

文學文享(8):Matlab繪圖學習之二維三維圖繪制及相關基礎操作

今天的分享就到這裡了。

如果您對今天的文章有獨特的想法,

歡迎給我們留言,

讓我們相約明天。

祝您今天過得開心快樂!

That's all for today's sharing.

If you have a unique idea about the article,

please leave us a message,

and let us meet tomorrow.

I wish you a nice day!

參考資料:

翻譯:

Google翻譯

文字:

https://space.bilibili.com/24014925/channel/seriesdetail?sid=1446602

圖檔:

自制

版權說明:

本文由LearningYard學苑整理并發出,如有侵權請背景留言溝通。

文案I姜瘋雨火

排版I姜瘋雨火

稽核IGoldfish

繼續閱讀