Chap.1 簡介與入門使用 方煒 台大生機系 彙整.

Slides:



Advertisements
Similar presentations
实验安排 本周六和下周六上机时间: 上午: 8 : 30~10 : 00 第一组 上午: 11 : 00~11 : 30 第二组 下午: 14 : 30~16 : 00 第三组.
Advertisements

國立成功大學工程科學系 Department of Engineering Science -National Cheng Kung University 控制與訊號處理實驗室 Control & Signal Processing Lab MATLAB/Simulink 教學.
Matlab 教學 Speaker :陳珮妮 Date : 2013/03/14 1. Outline  MATLAB 簡介  算術邏輯運算  Matlab 陣列  Matlab 矩陣 2.
第六讲 MATLAB 语言程序设计 6.1 MATLAB语言的函数的基本结构 6.2 全局、局部变量、子函数与私有目录
Dr. Baokun Li 经济实验教学中心 商务数据挖掘中心
-CHINESE TIME (中文时间): Free Response idea: 你周末做了什么?
‧姓名‧年級‧ ‧年月‧ Type out your Chinese name and grade Record your voice:
Type out your Chinese name and grade
SPSS统计软件的使用方法基础 主讲人:宋振世 (闵行校区) 电 话:
自衛消防編組任務職責 講 義 This template can be used as a starter file for presenting training materials in a group setting. Sections Right-click on a slide to add.
控制流程實作 胡百敬 精誠公司恆逸資訊 二○一七年三月十九日
Introduction to Matlab
Matlab教學 Speaker:林昱志 Date:2012/10/18.
張智星 清大資工系 多媒體檢索實驗室 MATLAB小傳與外觀 張智星 清大資工系 多媒體檢索實驗室.
1-1 MATLAB 小傳(1) 由MathWorks公司於1984年推出的 數學軟體。 名稱是由「矩陣實驗室﹙MATrix
1012 MATLAB 教學 彭奕翔 2013/02/27.
System Administration Practice Homework 2: Shell Programming
Operators and Expressions
全球工程師共同的語言 MathWorks 台灣總代理鈦思科技 指導老師 : 郭艷光教授 報告者 : 吳育驊
Matlab及其应用 鲍文 哈尔滨工业大学 先进动力控制与可靠性研究所
第1章 MATLAB概述 1.1 MATLAB 7.x简介 是Matrix Laboratory的缩写,它将计算、可视化和编程功能于一身,是一个开放的基于矩阵的交互式开发系统。主要用于数学计算、系统建模与仿真、数据分析与可视化等。(Mathworks始创于1984) MATLAB的系统结构.
第一章 概 述 1.1 MATLAB产品族简介 1.2 MATLAB的桌面环境 1.3 Command Windows和MATLAB指令
微積分網路教學課程 應用統計學系 周 章.
Chapter 1 用VC++撰寫程式 Text book: Ivor Horton.
MATLAB介紹.
Basis基本操作、使用者 管理與權限設定
第五讲 数据的分组、合并与转换.
簡易 Visual Studio 2010 C++ 使用手冊
統計套裝軟體 輔大統計資訊系 黃孝雲.
Write a letter in a proper format
Matlab M檔案 方煒 台大生機系.
數學與電腦 的初相識 汪群超 個人網址: 變有不可者三,有不可不變者三: 能力未至不可變也、 學識未敷不得變也、 功侯未到不能變也。
C 語言簡介 - 2.
第1章 MATLAB概述 编者.
XBRL未來發展趨勢 2009年12月 For information on applying this template onto existing presentations, refer to the notes on slide 3 of this presentation. The Input.
圖表製作 集中指標 0628 統計學.
第三章 项目设定.
重點 資料結構之選定會影響演算法 選擇對的資料結構讓您上天堂 程式.
数据分析绘图工具 ——Origin6.0.
SPSS-概述與資料處理 輔大統計資訊系 黃孝雲.
ANSYS基础与入门.
客户服务 询盘惯例.
引 言.
簡易 Visual Studio 2005 C++ 使用手冊
授課教授:張寶基 助教:梁凱雯 郭千豪 音視訊處理實驗室 2014 / 9 / 30
第1章 MATLAB操作基础 1.1 绪论 1.2 MATLAB概述 1.3 MATLAB的运行环境与安装 1.4 MATLAB集成环境 1.5 MATLAB帮助系统.
MATLAB 程式設計入門篇 初探MATLAB
MATLAB 程序设计语言 任课教师:刘毅 西安电子科技大学 ISN国家重点实验室.
資料結構 Data Structures Fall 2006, 95學年第一學期 Instructor : 陳宗正.
成品检查报告 Inspection Report
Mechanics Exercise Class Ⅰ
Guide to a successful PowerPoint design – simple is best
MATLAB 程式設計入門篇 初探MATLAB
中央社新聞— <LTTC:台灣學生英語聽說提升 讀寫相對下降>
Unit 7 Lesson 20 九中分校 刘秀芬.
從 ER 到 Logical Schema ──兼談Schema Integration
MATLAB 程式設計入門篇 初探MATLAB
Compute System Administration Homework 2: Shell Script
计算机问题求解 – 论题1-5 - 数据与数据结构 2018年10月16日.
Create and Use the Authorization Objects in ABAP
第一单元 第1课 Matlab概述 1.MATLAB 2.工具箱 3.高效数值计算功能 4.完备的计算结果和编程可视化功能
符号 目录 页 绝对寻址和符号寻址… 符号寻址- 概述… 打开符号表 编辑:查找和替换…… 查看:过滤器 … 查看:排序…… 符号表:导出
Introduction to Matlab
第1章 MATLAB操作基础 1. 1 MATLAB概述 1. 2 MATLAB的运行环境与安装 1. 3 MATLAB集成环境 1
MATLAB 实用教程.
怎樣把同一評估 給與在不同班級的學生 How to administer the Same assessment to students from Different classes and groups.
Arguments to the main Function and Final Project
原版:清大資工系 張智星 新增版:方煒 台大生機系
Section 1 Basic concepts of web page
When using opening and closing presentation slides, use the masterbrand logo at the correct size and in the right position. This slide meets both needs.
Presentation transcript:

Chap.1 簡介與入門使用 方煒 台大生機系 彙整

小傳(1) 由MathWorks公司於1984年推出的數學軟體。 名稱是由「矩陣實驗室」﹙MATrix LABoratory)所合成。 MATLAB為各種動態系統模擬、數位訊號處理、科學計算、科學目視等領域的標準程式語言。 MATLAB 的許多的核心計算技術是源自於 LINPACK 及 EISPACK 。

小傳(2) MATLAB早在 1978 年即已現身,是用 Fortran 撰寫的免費軟體,其作者是當時任教於新墨西哥大學的 Cleve Moler 教授。 Jack Little(又稱為 John Little)將 MATLAB 以C語言重寫,並於 1984 年成立 MathWorks公司,首次推出 MATLAB 商用版。 MathWorks在 Newsgroup 上進行對使用者的技術指導,在 WWW 興起之後,就提供各項技術支援與搜尋功能,並在內聯網(Intranet)方面,以 Web 與資料庫的整合來進行軟體 bug 的追蹤、修復與管理。

簡介 MATLAB 早期以矩陣運算為主,第 4 版推出握把式圖形(Handle Graphics),第 5 版中允許使用者建立許多不同的資料型態,(如多維陣列、結構陣列、異質陣列等)。 MATLAB 是一個計算核心,圍繞著這個計算核心,有許多針對不同應用所開發的應用程式,稱為工具箱(Toolboxes) 。

Simulink 及 Stateflow Simulink 專用於連續或離散時間的動態系統模擬。 Simulink 是一個模擬核心,圍繞著這個核心所開發的應用程式稱為方塊集(Blocksets)。 Stateflow 則用於模擬有限狀態機(Finite State Machines)或事件驅動系統(Event-driven Systems)。

MATLAB、Simulink 及 Stateflow 由現有 Simulink 與 Stateflow 的 C 程式碼自動產生功能,以及定點運算方塊集(Fixed-point Blockset)與 C 程式碼至 VHDL 的自動轉換功能,可看出「高階的系統模擬」或「低階的晶片演算法設計」,都可用 MATLAB/Simulink/Stateflow 及相關的工具箱來達成。 MATLAB Toolboxes Compiler Simulink Stateflow Blocksets RTW Coder

Toolboxes Fuzzy logic Communications Garch Control system Curve fitting Data acquisition Database Datafeed Filter design Financial Financial derivatives Financial time series Fuzzy logic Garch Image processing Instrument control LMI control Matlab link for code composer studio Mapping Model predictive control Model-based calibration

Toolboxes Mu-analysis and synthesis Neural Network Optimization Partial Differential Robust control Signal processing Spline Statistics Symbolic math System identification Virtual reality Wavelet

第五版的外觀 啟動方式:( 以MATLAB 5.3版R11為主) 以滑鼠點選兩次桌面上的MATLAB圖示( ) 在『開始』的主選單下,選取『程式集/ Matlab / MATLAB 5.3』 於 DOS 視窗輸入下列命令來啟動 MATLAB: {MATLAB 根目錄}\bin\matlab

下拉式選單(Pull-down Menu) 下拉式選單: File,Edit,View,Window,Help 等,其中較重要的是 File/Preference 下的圖形介面,可以設定個人的喜好值,如下:

工作空間瀏覽器 圖示為 ,可用於瀏覽位於工作空間中的變數,包含其名稱、資料形態、維度大小、佔用位元大小等,其外觀如下:

路徑瀏覽器 圖示為 ,功能是以視窗面的方式來對搜尋路徑進行新增、修改或刪除等功能,其外觀如下:

Simulink 方塊庫瀏覽器 Simulink 是以方塊圖為基礎的動態模擬系統,是架於 MATLAB 之上的另一個產品。

線上支援視窗 圖示為 ,可開啟 MATLAB 的線上支援視窗,並將 MATLAB 所有的指令分門別類。外觀如下:

第六版的外觀(1) MATLAB 第六版( 以6.5 (R13)版為主 )的啟動方法和第五版相同。 介面是以 Java 撰寫,因此第一次啟動時間較久。外觀如下:

第六版的外觀(2) MATLAB 桌面被分割成三個小視窗: 命令視窗 Command Window 工作空間變數列表Workspace Window 命令歷史列表 List of Command History

「View」的下拉式選單(1) 較常用的五個視窗 Profiler: 開啟或關閉”計時器控制頁”。 help: 開啟或關閉”技術支援頁”。 Command Window: 開或關”命令視窗”。 Command History: 開或關”命令歷史列表”。 Current Directory: 開或關”目前目錄檢視窗”。 Workspace: 開啟或關閉”工作空間變數列表”。 Launch Pad: 開啟或關閉”啟動面版”。 前四者為預設(default)的視窗 Profiler: 開啟或關閉”計時器控制頁”。 help: 開啟或關閉”技術支援頁”。

「View」的下拉式選單(2) Undock from Desktop

「View」的下拉式選單(3) 點選View/Desktop Layout/Five Panel可同時開啟其中較重要的五個視窗: 點選View/Desktop Layout/Default可恢復原狀。

「 File 」的下拉式選單(1) 請輸入 A=magic(3); 點選File/New/M file可叫出程式編輯器 點選File/Save 以test1 檔名儲存於預設目錄 請輸入 A=magic(3);

「 File 」的下拉式選單(2) 關閉程式編輯器 在Command Window 輸入Test1執行該程式 連續輸入三個指令如Command history 所示 輸出結果如Command Window 視窗所示

「 File 」的下拉式選單(3) 點選File/Open 可叫出目前目錄 選取 test1叫出該M file 輸入新的指令如右所示 到Command Window 視窗看執行結果 持續輸入D=A’ 輸入clc 清除Command Window 輸入clear A清除變數A 輸入clear all 清除所有變數

「 File 」的下拉式選單(4) 點選File/Set Path可建立程式工作區, Matlab 會依照預設的path 與順序來尋找所要的檔案。

第七版的外觀 MATLAB 7.0 (R14) 發行於 2004 年六月,其啟動方法和第六版相同。

「活頁夾」型式的MATLAB桌面 點選Desktop/Desktop Layout/All Tabbed可將各個小視窗改為「活頁夾」的型式。 (由左圖可以看出 共有六個小視窗) 若要回到預設的桌面配置,可點選Desktop/Desktop Layout/Default

Command Description addpath dirname Adds the directory dirname to the search path. cd dirname Changes the current directory to dirname. dir Lists all files in the current directory. dir dirname Lists all the files in the directory dirname. path Displays the MATLAB search path. pathtool Starts the Set Path tool.

System, Directory, and File Commands Command Description pwd Displays the current directory. rmpath dirname Removes the directory dirname from the search path. what Lists the MATLAB-specific files found in the current working directory. Most data files and other non-MATLAB files are not listed. Use dir to get a list of all files. what dirname Lists the MATLAB-specific files in directory dirname.

The default MATLAB Desktop.

Entering Commands and Expressions MATLAB retains your previous keystrokes. Use the up-arrow key to scroll back back through the commands. Press the key once to see the previous entry, and so on. Use the down-arrow key to scroll forward. Edit a line using the left- and right-arrow keys the Backspace key, and the Delete key. Press the Enter key to execute the command.

Commands for managing the work session Command Description clc Clears the Command window. clear Removes all variables from memory. clear v1 v2 Removes the variables v1 and v2 from memory. exist(‘var’)Determines if a file or variable exists having the name ‘var’. quit Stops MATLAB.

who Lists the variables currently in memory. whos Lists the current variables and sizes, and indicates if they have imaginary parts. : Colon; generates an array having regularly spaced elements. , Comma; separates elements of an array. ; Semicolon; suppresses screen printing; also denotes a new row in an array. ... Ellipsis; continues a line.

When you type problem1 1. MATLAB first checks to see if problem1 is a variable and if so, displays its value. 2. If not, MATLAB then checks to see if problem1 is one of its own commands, and executes it if it is. 3. If not, MATLAB then looks in the current directory for a file named problem1.m and executes problem1 if it finds it. 4. If not, MATLAB then searches the directories in its search path, in order, for problem1.m and then executes it if found.

Two ways to perform operations in MATLAB 1. In the interactive mode, in which all commands are entered directly in the Command window, or By running a MATLAB program stored in script file. You can run the file by typing its name at the Command window prompt.

直譯器 Interpreter >> 8/10 ans = 0.8000 >> 5*ans 4 >> s=20*r s = 16

Polynomial Roots To find the roots of x3 – 7x2 + 40x – 34 = 0, the session is >>a = [1,-7,40,-34]; >>roots(a) ans = 3.0000 + 5.000i 3.0000 - 5.000i 1.0000 The roots are x = 1 and x = 3 ± 5i.

A graphics window showing a plot.

Some MATLAB plotting commands plot(x,y) Generates a plot of the array y versus the array x on rectilinear axes. title(’text’) Puts text in a title at the top of the plot. xlabel(’text’) Adds a text label to the horizontal axis (the abscissa). ylabel(’text’) Adds a text label to the vertical axis (the ordinate).

Scalar Arithmetic Operations Symbol Operation MATLAB form ^ exponentiation: ab a^b * multiplication: ab a*b / right division: a/b a/b \ left division: b/a a\b + addition: a + b a + b - subtraction: a - b a - b

使用變數與基本運算 一般數學符號運算 在MATLAB 命令視窗(Command Window)內的提示符號(>>)之後輸入運算式,並按入 Enter 鍵即可。例如: >> (5*2+3.5)/5 ans = 2.7000 若不想讓 MATLAB 每次都顯示運算結果,只需在運算式最後加上分號(;)即可,例如: >> (5*2+3.5)/5; >> 1+1 >> 2*3 >> 5.23e12/6.2e5 >> exp(-3) >> atan2(-1,2) >> sin(5) In radians

加入註解 若要加入註解(Comments),可以使用百分比符號(%)例如: >> y = (5*2+3.5)/5; % 將運算結果儲存在變數 y,但不用顯示於螢幕 >> z = y^2 % 將運算結果儲存在變數 z,並顯示於螢幕 z = 7.2900

註解 COMMENTS The comment symbol may be put anywhere in the line. MATLAB ignores everything to the right of the % symbol. For example, >>% This is a comment. >>x = 2+3 % So is this. x = 5 Note that the portion of the line before the % sign is executed to compute x.

m 檔案 (script file) 若要一次執行大量的 MATLAB 指令,可將這些指令存放於一個副檔名為 m 的檔案,並在 指令提示號(>>)下鍵入此檔案主檔名即可。 >> pwd % 顯示目前的工作目錄 >> dir 顯示目前工作目錄的內容 >> cd 可改變工作目錄 >> type myTest.m % 顯示 myTest.m 的內容 >> myTest % 執行 myTest.m “Save and Run” shortcut key, F5. m file中程式太長可用… 連接a=sin(x)*exp(-y)*... log(z)+sqrt(b);

Keep in mind when using script files 1. The name of a script file must begin with a letter, and may include digits and the underscore character, up to 31 characters. 2. Do not give a script file the same name as a variable. 3. Do not give a script file the same name as a MATLAB command or function. You can check to see if a command, function or file name already exists by using the exist command.

The Assignment Operator = Typing x = 3 assigns the value 3 to the variable x. We can then type x = x + 2. This assigns the value 3 + 2 = 5 to x. But in algebra this implies that 0 = 2. In algebra we can write x + 2 = 20, but in MATLAB we cannot. In MATLAB the left side of the = operator must be a single variable. The right side must be a computable value.

Numeric Display Formats Command Description and Example format short Four decimal digits (the default); 13.6745. format long 14 decimal digits; 17.27484029463547. format short e Five digits (four decimals) plus exponent; 6.3792e+03. format long e 16 digits (15 decimals) plus exponent; 6.379243784781294e–04.

Some plotting commands Description [x,y] = ginput(n) Enables the mouse to get n points from a plot, and returns the x and y coordinates in the vectors x and y, which have a length n. grid Puts grid lines on the plot. gtext(’text’) Enables placement of text with the mouse.

Command window with the Editor/Debugger open.

Getting Help Throughout each chapter margin notes identify where key terms are introduced. Each chapter contains tables summarizing the MATLAB commands introduced in that chapter. At the end of each chapter is a summary guide to the commands covered in that chapter. Appendix A contains tables of MATLAB commands, grouped by category, with the appropriate page references. There are three indexes. The first lists MATLAB commands and symbols, the second lists Simulink blocks, and the third lists topics.

The Help Navigator contains four tabs: Contents: a contents listing tab, Index: a global index tab, Search: a search tab having a find function and full text search features, and Demos: a bookmarking tab to start built-in demonstrations.

Help Navigator

線上支援 help funcname :用來查詢已知指令的用法 >>help atan2 lookfor topic:用來尋找未知的指令或以topic為主題的相關訊息。找到所需的指令後,即可用 help 進一步找出其用法。 譬如輸入 help elliptic 查不到任何內容. 但輸入 lookfor elliptic 有進一步訊息,原來拼錯字了 help ellipke helpwin 或 helpdesk:產生線上支援視窗,其效果和直接點選 MATLAB 命令視窗工作列的圖示是一樣的。 doc funcname:展示funcname函數的線上支援。

搜尋路徑 若要檢視 MATLAB 已設定的搜尋路徑,鍵入 path 指令即可: 若只要查詢某一特定指令所在的搜尋路徑,可用 which 指令 要將目錄加入 MATLAB 的搜尋路徑之最前端,使用 addpath 指令,如 >> addpath d:\matlabbook 要將目錄加入 MATLAB 的搜尋路徑之最末,使用 addpath 指令,如 >> addpath d:\matlabbook –end 要將目錄自 MATLAB 的搜尋路徑移除,使用 rmpath 指令,如 >> rmpath d:\matlabbook 搜尋路徑定義在matlabrc.m 檔案內,可直接修改該檔案

離開 MATLAB 在命令視窗內,鍵入 exit 指令。 在命令視窗內,鍵入 quit 指令。 直接關閉 MATLAB 的命令視窗。

End of Chapter 1