zoukankan      html  css  js  c++  java
  • matlab安装和入门

    下载iso镜像:

    ISO镜像下载地址链接: http://pan.baidu.com/s/1i31bu5J 密码: obo1

    单独破解文件下载链接: http://pan.baidu.com/s/1c0CGQsw 密码: h98h
    安装及破解步骤
    1) 运行"X:setup.exe"或者运行 "X:inwin32setup.exe" (如果你想在64位操作系统上安装32位的MATLAB)
    2) 选择 "install manually without using the internet"
    3) 当需要输入"file installation key"时,使用以下密钥
    12313-94680-65562-90832
    4) 安装 Matlab (如果你想节约空间,请选择custom安装方式,勾选你需要的工具箱)
    5) 当需要激活时,选择"activation without internet"
    6) 当需要选择授权文件时,选择 "X:seriallicense.lic" 
    7) 根据你安装的MATLAB版本,复制文件夹"X:serialMatlabX32" 或 "X:serialMatlabX64" 下的bin文件夹到MATLAB的安装目录,替换已存在的文件。对于XP以上操作系统,此步可能需要管理员权限

    2014a版本特性:
    MathWorks 今天宣布推出其  MATLAB 和 Simulink 产品系列的 Release 2014a (R2014a) 版本。R2014a 包括 MATLAB 和 Simulink 的新功能以及 81 个其他产品的更新和补丁修复。

    MATLAB 产品系列

        MATLAB:Raspberry Pi 和网络摄像头硬件支持包 
        Optimization Toolbox:混合整数线性规划 (MILP) 解算器
        Statistics Toolbox:为每对象具有多个测量值的数据进行重复测量数据建模
        Image Processing Toolbox:使用 MATLAB Coder 为 25 个函数生成 C 代码,为 5 个函数实现 GPU 加速
        Econometrics Toolbox:状态-空间模型、缺失数据情况下自校准的卡尔曼滤波器,以及ARIMA/GARCH 模型性能增强
        Financial Instruments Toolbox:对偶曲线构建,用于计算信用敞口和敞口概况的函数,以及利率上限、利率下限和掉期期权的布莱克模型定价
        SimBiology:提供用于模型开发的模型估算和桌面增强的统一函数
        System Identification Toolbox:递归最小二乘估算器和在线模型参数估算模块
        MATLAB Production Server:实现客户端与服务器之间的安全通讯以及动态请求创建

    Simulink 产品系列

        Simulink:用于定义和管理与模型关联的设计数据的数据字典。
        Simulink:用于多核处理器和 FPGA 的算法分割和定位的单一模型工作流程
        Simulink:为LEGO MINDSTORMS EV3、Arduino Due 和 Samsung Galaxy Android 设备提供内置支持
        Stateflow:提供了上下文相关的 Tab 键自动补全功能来完成状态图
        Simulink Real-Time:仪表板、高分辨率目标显示器和FlexRay 协议支持,以及合并了xPC Target 和 xPC Target Embedded Option 的功能
        SimMechanics:STEP 文件导入和接口的总约束力计算
        Simulink Report Generator:用于在 Simulink 视图中丰富显示内容的对象检查器和通知程序

    用于在 MATLAB 和 Simulink 中进行设计的系统工具箱 (System Toolbox)

        Computer Vision System Toolbox:立体视觉和光学字符识别 (OCR) 功能

    代码生成

        Embedded Coder:支持将 AUTOSAR 工具的变更合并到 Simulink 模型中
        Embedded Coder:ARM Cortex-A 使用 Ne10 库优化了代码生成
        HDL Coder:枚举数据类型支持和时钟频率驱动的自动流水线操作
        HDL Verifier:通过JTAG对Altera 硬件进行 FPGA 在环仿真

    The desktop includes these panels:

    • Current Folder — Access your files.

    • Command Window — Enter commands at the command line, indicated by the prompt (>>).

    • Workspace — Explore data that you create or import from files. 探索数据

    As you work in MATLAB, you issue commands that create variables and call functions. For example, create a variable named a by typing this statement at the command line:

    a = 1

    MATLAB adds variable a to the workspace and displays the result in the Command Window.

    a = 
    
         1

    Create a few more variables.

    b = 2
    
    b = 
    
         2
    c = a + b
    c = 
    
         3
    d = cos(a)
    d = 
    
        0.5403

    When you do not specify an output variable, MATLAB uses the variable ans, short for answer, to store the results of your calculation.当你不指定输出变量时,matlab使用变量ans(answer的简称)来存储计算的结果。

    sin(a)
    ans =
    
        0.8415

    If you end a statement with a semicolon, MATLAB performs the computation, but suppresses the display of output in the Command Window. 输入;抑制输出结果的展示。

    e = a*b;

    You can recall previous commands by pressing the up- and down-arrow keys, ↑ and ↓. Press the arrow keys either at an empty command line or after you type the first few characters of a command. For example, to recall the command b = 2, type b, and then press the up-arrow key.

    按up或down键来调用先前的命令。


    Matrices and Arrays

    MATLAB is an abbreviation for "matrix laboratory."(matrix laboratory矩阵实验室) While other programming languages mostly work with numbers one at a time, MATLAB® is designed to operate primarily on whole matrices and arrays.

    All MATLAB variables are multidimensional arrays, no matter what type of data. A matrix is a two-dimensional array often used for linear algebra.

    所有的matlalb变量都是多维数组,不论是何种数据类型。一个matrix是二维数组。

    Array Creation

    To create an array with four elements in a single row, separate the elements with either a comma (,) or a space.(使用逗号或空格分离。

    a = [1 2 3 4]

    returns

    a =
    
         1     2     3     4

    This type of array is a row vector.

    To create a matrix that has multiple rows, separate the rows with semicolons.分离每个row用;

    a = [1 2 3; 4 5 6; 7 8 10]
    a =
    
         1     2     3
         4     5     6
         7     8    10

    Another way to create a matrix is to use a function, such as oneszeros, or rand. For example, create a 5-by-1 column vector of zeros.

    z = zeros(5,1)
    z =
    
         0
         0
         0
         0
         0

    Matrix and Array Operations

    MATLAB allows you to process all of the values in a matrix using a single arithmetic operator or function.

    matlab允许你在matrix中用单一算术运算符处理所有的值。

    a + 10
    ans =
    
        11    12    13
        14    15    16
        17    18    20
    sin(a)
    ans =
    
        0.8415    0.9093    0.1411
       -0.7568   -0.9589   -0.2794
        0.6570    0.9894   -0.5440

    To transpose a matrix, use a single quote ('): 用'转置矩阵

    a'
    ans =
    
         1     4     7
         2     5     8
         3     6    10

    You can perform standard matrix multiplication, which computes the inner products between rows and columns, using the * operator. For example, confirm that a matrix times its inverse returns the identity matrix:

    p = a*inv(a)
    p =
    
        1.0000         0   -0.0000
             0    1.0000         0
             0         0    1.0000

    Notice that p is not a matrix of integer values. MATLAB stores numbers as floating-point values, and arithmetic operations are sensitive to small differences between the actual value and its floating-point representation. You can display more decimal digits using the format command:

    format long
    p = a*inv(a)
    p =
    
       1.000000000000000                   0  -0.000000000000000
                       0   1.000000000000000                   0
                       0                   0   0.999999999999998

    Reset the display to the shorter format using

    format short

    format affects only the display of numbers, not the way MATLAB computes or saves them.

    To perform element-wise multiplication rather than matrix multiplication, use the .* operator:

    实现矩阵按元素逐位相乘而不是矩阵乘法,使用.*。

    p = a.*a
    p =
    
         1     4     9
        16    25    36
        49    64   100

    The matrix operators for multiplication, division, and power each have a corresponding array operator that operates element-wise. For example, raise each element of a to the third power:做幂运算

    a.^3
    ans =
    
               1           8          27
              64         125         216
             343         512        1000

    Concatenation

    Concatenation is the process of joining arrays to make larger ones. In fact, you made your first array by concatenating its individual elements. The pair of square brackets [] is the concatenation operator.事实上,你做的第一个array,[1,2,3]就是连接单个的元素而成为了array。[]是连接运算符

    A = [a,a]
    A =
    
         1     2     3     1     2     3
         4     5     6     4     5     6
         7     8    10     7     8    10

    Concatenating arrays next to one another using commas is called horizontal concatenation. Each array must have the same number of rows. Similarly, when the arrays have the same number of columns, you can concatenate vertically using semicolons.

    使用逗号连接的叫水平连接,每个array必须有相同的行数。垂直连接使用分号。

    A = [a; a]
    A =
    
         1     2     3
         4     5     6
         7     8    10
         1     2     3
         4     5     6
         7     8    10

    Complex Numbers

    Complex numbers have both real and imaginary parts, where the imaginary unit is the square root of –1.

    sqrt(-1)
    ans =
    
       0.0000 + 1.0000i

    To represent the imaginary part of complex numbers, use either i or j.

    c = [3+4i, 4+3j; -i, 10j]
    c =
    
       3.0000 + 4.0000i   4.0000 + 3.0000i
       0.0000 - 1.0000i   0.0000 +10.0000i

    Array Indexing

    Every variable in MATLAB® is an array that can hold many numbers. When you want to access selected elements of an array, use indexing.

    For example, consider the 4-by-4 magic square A:(参考:http://zh.wikipedia.org/wiki/%E5%B9%BB%E6%96%B9

    A = magic(4)
    A =
        16     2     3    13
         5    11    10     8
         9     7     6    12
         4    14    15     1

    There are two ways to refer to a particular element in an array. The most common way is to specify row and column subscripts, such as

    A(4,2)
    ans =
        14

    Less common, but sometimes useful, is to use a single subscript that traverses down each column in order:

    A(8)
    ans =
        14

    Using a single subscript to refer to a particular element in an array is called linear indexing.使用单一的下标叫线性索引。

    If you try to refer to elements outside an array on the right side of an assignment statement, MATLAB throws an error.

    test = A(4,5)
    Attempted to access A(4,5); index out of bounds because size(A)=[4,4].
    在赋值表达式的右边索引超界会抛出错误。

    However, on the left side of an assignment statement, you can specify elements outside the current dimensions. The size of the array increases to accommodate the newcomers.

    A(4,5) = 17
    A =
        16     2     3    13     0
         5    11    10     8     0
         9     7     6    12     0
         4    14    15     1    17
    在赋值表达式左边索引超界不会抛出错误,array的size会增加以适应新来者。

    To refer to multiple elements of an array, use the colon operator, which allows you to specify a range of the form start:end. For example, list the elements in the first three rows and the second column of A:

    使用start:end(包括end)来表示一个range。

    A(1:3,2)
    ans =
         2
        11
         7

    The colon alone, without start or end values, specifies all of the elements in that dimension. For example, select all the columns in the third row of A:

    只有:,没有start和end,表示所有

    A(3,:)
    ans =
         9     7     6    12     0

    The colon operator also allows you to create an equally spaced vector of values using the more general form start:step:end.

    B = 0:10:100
    B =
    
         0    10    20    30    40    50    60    70    80    90   100

    If you omit the middle step, as in start:end, MATLAB uses the default step value of 1.

    Workspace Variables

    The workspace contains variables that you create within or import into MATLAB® from data files or other programs. For example, these statements create variables A and B in the workspace.

    A = magic(4);
    B = rand(3,5,2);

    You can view the contents of the workspace using whos.

    whos
      Name      Size             Bytes  Class     Attributes
    
      A         4x4                128  double              
      B         3x5x2              240  double              

    The variables also appear in the Workspace pane on the desktop.

    Workspace variables do not persist after you exit MATLAB. Save your data for later use with the savecommand,

    save myfile.mat

    Saving preserves the workspace in your current working folder in a compressed file with a .mat extension, called a MAT-file.

    To clear all the variables from the workspace, use the clear command.

    Restore data from a MAT-file into the workspace using load.

    load myfile.mat

    Character Strings

    character string is a sequence of any number of characters enclosed in single quotes. You can assign a string to a variable.

    myText = 'Hello, world';         单引号表示字符串,双引号错误。

    If the text includes a single quote, use two single quotes within the definition.

    otherText = 'You''re right'
    otherText =
    
    You're right

    myText and otherText are arrays, like all MATLAB® variables. Their class or data type is char, which is short for character.

    mytext和othertext是同所有的matlab变量一样,是array。它们的data type是char。

    whos myText
      Name        Size            Bytes  Class    Attributes
    
      myText      1x12               24  char               

    You can concatenate strings with square brackets, just as you concatenate numeric arrays.

    用【】连接字符串,仅仅像连接numeric arrays一样。

    longText = [myText,' - ',otherText]
    longText =
    
    Hello, world - You're right

    To convert numeric values to strings, use functions, such as num2str or int2str.

    f = 71;
    c = (f-32)/1.8;
    tempText = ['Temperature is ',num2str(c),'C']
    tempText =
    
    Temperature is 21.6667C

    Calling Functions

    MATLAB® provides a large number of functions that perform computational tasks. Functions are equivalent to subroutines or methods in other programming languages.

    To call a function, such as max, enclose its input arguments in parentheses:

    A = [1 3 5];
    max(A);

    If there are multiple input arguments, separate them with commas:

    B = [10 6 4];
    max(A,B);
    函数多个参数用逗号分隔。
    (使用max 矩阵维度必须一致)。
    结果:

    ans =

    10 6 5

    Return output from a function by assigning it to a variable:

    maxA = max(A);

    When there are multiple output arguments, enclose them in square brackets:

    [maxA,location] = max(A);

    Enclose any character string inputs in single quotes:

    disp('hello world');

    To call a function that does not require any inputs and does not return any outputs, type only the function name:

    clc

    The clc function clears the Command Window.

    调用一个函数,没有任何input和output,仅仅打函数名字即可。

    2-D and 3-D Plots

    Line Plots

    To create two-dimensional line plots, use the plot function. For example, plot the value of the sine function from 0 to $2pi$ :

    x = 0:pi/100:2*pi;
    y = sin(x);
    plot(x,y)
    
    

    You can label the axes and add a title.

    xlabel('x')
    ylabel('sin(x)')
    title('Plot of the Sine Function')
    
    

    By adding a third input argument to the plot function, you can plot the same variables using a red dashed line.

    plot(x,y,'r--')


    The 'r--' string is a line specification. Each specification can include characters for the line color, style, and marker. A marker is a symbol that appears at each plotted data point, such as a +o, or *. For example,'g:*' requests a dotted green line with * markers.

     

    Notice that the titles and labels that you defined for the first plot are no longer in the current figure window. By default, MATLAB® clears the figure each time you call a plotting function, resetting the axes and other elements to prepare the new plot.

    每次调用plot都会清除以前的配置。

    To add plots to an existing figure, use hold.

    x = 0:pi/100:2*pi;
    y = sin(x);
    plot(x,y)
    
    hold on
    
    y2 = cos(x);
    plot(x,y2,'r:')
    legend('sin','cos')
    Until you use hold off or close the window, all plots appear in the current figure window.

    3-D Plots

    Three-dimensional plots typically display a surface defined by a function in two variables, z = f(x,y) .

    To evaluate z, first create a set of (x,y) points over the domain of the function using meshgrid.

    [X,Y] = meshgrid(-2:.2:2);
    Z = X .* exp(-X.^2 - Y.^2);
    

    Then, create a surface plot.

    surf(X,Y,Z)
    

     

    Both the surf function and its companion mesh display surfaces in three dimensions. surf displays both the connecting lines and the faces of the surface in color. mesh produces wireframe surfaces that color only the lines connecting the defining points.

    Subplots

    You can display multiple plots in different subregions of the same window using the subplot function.

    For example, create four plots in a 2-by-2 grid within a figure window.

    t = 0:pi/10:2*pi;
    [X,Y,Z] = cylinder(4*cos(t));
    subplot(2,2,1); mesh(X); title('X');
    subplot(2,2,2); mesh(Y); title('Y');
    subplot(2,2,3); mesh(Z); title('Z');
    subplot(2,2,4); mesh(X,Y,Z); title('X,Y,Z');
    

     

    The first two inputs to the subplot function indicate the number of plots in each row and column. The third input specifies which plot is active.

    Programming and Scripts

    The simplest type of MATLAB® program is called a script. A script is a file with a .m extension that contains multiple sequential lines of MATLAB commands and function calls. You can run a script by typing its name at the command line.

    Sample Script

    To create a script, use the edit command,

    edit plotrand

    This opens a blank file named plotrand.m. Enter some code that plots a vector of random data:

    n = 50;
    r = rand(n,1);
    plot(r)

    Next, add code that draws a horizontal line on the plot at the mean:

    m = mean(r);
    hold on
    plot([0,n],[m,m])
    hold off
    title('Mean of Random Uniform Data')

    Whenever you write code, it is a good practice to add comments that describe the code. Comments allow others to understand your code, and can refresh your memory when you return to it later. Add comments using the percent (%) symbol.

    % Generate random data from a uniform distribution
    % and calculate the mean. Plot the data and the mean.
     
    n = 50;            % 50 data points
    r = rand(n,1);
    plot(r)
     
    % Draw a line from (0,m) to (n,m)
    m = mean(r);
    hold on
    plot([0,n],[m,m])
    hold off
    title('Mean of Random Uniform Data')

    Save the file in the current folder. To run the script, type its name at the command line:

    plotrand

    You can also run scripts from the Editor by pressing the Run button, .

    Loops and Conditional Statements

    Within a script, you can loop over sections of code and conditionally execute sections using the keywordsforwhileif, and switch.

    For example, create a script named calcmean.m that uses a for loop to calculate the mean of five random samples and the overall mean.

    nsamples = 5;
    npoints = 50;
    
    for k = 1:nsamples
        currentData = rand(npoints,1);
        sampleMean(k) = mean(currentData);
    end
    overallMean = mean(sampleMean)

    Now, modify the for loop so that you can view the results at each iteration. Display text in the Command Window that includes the current iteration number, and remove the semicolon from the assignment tosampleMean.

    for k = 1:nsamples
       iterationString = ['Iteration #',int2str(k)];
       disp(iterationString)
       currentData = rand(npoints,1);
       sampleMean(k) = mean(currentData)
    end
    overallMean = mean(sampleMean)

    When you run the script, it displays the intermediate results, and then calculates the overall mean.

    calcmean
    Iteration #1
    
    sampleMean =
    
        0.3988
    
    Iteration #2
    
    sampleMean =
    
        0.3988    0.4950
    
    Iteration #3
    
    sampleMean =
    
        0.3988    0.4950    0.5365
    
    Iteration #4
    
    sampleMean =
    
        0.3988    0.4950    0.5365    0.4870
    
    Iteration #5
    
    sampleMean =
    
        0.3988    0.4950    0.5365    0.4870    0.5501
    
    
    overallMean =
    
        0.4935

    In the Editor, add conditional statements to the end of calcmean.m that display a different message depending on the value of overallMean.

    if overallMean < .49
       disp('Mean is less than expected')
    elseif overallMean > .51
       disp('Mean is greater than expected')
    else
       disp('Mean is within the expected range')
    end

    Run calcmean and verify that the correct message displays for the calculated overallMean. For example:

    overallMean =
    
        0.5178
    
    Mean is greater than expected

    Script Locations

    MATLAB looks for scripts and other files in certain places. To run a script, the file must be in the current folder or in a folder on the search path.

    By default, the MATLAB folder that the MATLAB Installer creates is on the search path. If you want to store and run programs in another folder, add it to the search path. Select the folder in the Current Folder browser, right-click, and then select Add to Path.

    Help and Documentation

    All MATLAB® functions have supporting documentation that includes examples and describes the function inputs, outputs, and calling syntax. There are several ways to access this information from the command line:

    • Open the function documentation in a separate window using the doc command.

      doc mean (会打开文档帮助器)
    • Display function hints (the syntax portion of the function documentation) in the Command Window by pausing after you type the open parentheses for the function input arguments.

      mean(
    • View an abbreviated text version of the function documentation in the Command Window using the helpcommand.

      help mean  (直接显示abbr text)

    Access the complete product documentation by clicking the help icon .

  • 相关阅读:
    利用消息机制实现.NET AOP(面向方面编程)--通过RealProxy实现 zz
    A Taste of AOP from Solving Problems with OOP and Design Patterns (Part II) zz
    在.Net中使用异步(一)
    在.Net中使用异步(二)
    技术人员的误区(zz)
    A Taste of AOP from Solving Problems with OOP and Design Patterns (Part III) zz
    利用矩阵进行坐标系转换
    如何选择开源许可证[zz]
    .Net,你为什么会慢
    理解 Thread.Sleep 函数
  • 原文地址:https://www.cnblogs.com/youxin/p/3859923.html
Copyright © 2011-2022 走看看