MATLAB Learning Notes (vi): Numerical arrays and vectorization operations _-_1

Source: Internet
Author: User

3.2 Creation and search of numerical arrays

3.2. Creation of 11-D arrays

For the purpose of creating one-dimensional arrays, there are roughly two categories: an array of independent variables and an array of common variables.

1. Increment/Decrement creation of one-dimensional arrays

"Colon" generation method

X=a:inc:b

A is the first element of the Array, Inc is the sampling interval, and if (b-a) is an integer multiple of INC, the last element in the array is equal to B, otherwise less than B

Inc can be omitted, default is 1

Linear fixed-point method

X=linspace (A,b,n)
An array of linear equal intervals, with a A, B, to the left and right endpoints

Such as

>> clear>> x=linspace (1,10,10) x =     1     2     3     4     5     6     7     8     9    10

2 creation of other types of one-dimensional arrays

input randomly, random array (produces 1 or less), and can be transpose to generate one-dimensional column array

>> x=[1,2,3]x =     1     2     3>> x=rand (1,5) x =    0.5684    0.0188    0.6176    0.6121    0.6169>> x= (1:6) ' x =     1     2     3     4     5     6

3.2. Creation of 22-D arrays

1 small-scale array direct input

This should be more familiar. The first section also reads: Click to open the link

2. Medium scale array Array Editor creation method

1. Click the icon in the work interval (Workspace) New variable


, create a variable named unnamed, double-click the variable name, the following interface appears


By manually entering data, save it last (preferably saved)

For renaming, you can change the variable name by clicking the variable name in the work interval

Verify


And the above input is the corresponding:


3 There is also a kind of M file creation method is also quite troublesome. I'll talk later.

4 Creating an array with MATLAB functions

Diag Generating diagonal arrays

Eye Generating Unit Array

Magic cube Array (what ghost)

Rand produces evenly distributed random arrays

Randn generating a random array of normal distributions

Ones produces a full 1 array

Zeros produces a full 0 array

>> clear>> ones (2,2) ans =     1     1     1     1>> rand (2,2) ans =    0.9437    0.3595    0.6818    0.4370>> randn (2,2) ans =   -0.4326    0.1253   -1.6656    0.2877>> a=eye (2) A =     1     0     0     1>> diag (a) ans =     1     1>> diag (diag (A)) ans =     1     0     0     1

MATLAB Learning Notes (vi): Numerical arrays and vectorization operations _-_1

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.