matlab2014a Help and Reference page Chinese translation Tutorials-array indexing

Source: Internet
Author: User



The Town field poem: The Compassion Heart Ji Shan, for the predestined person bigger proof. Lead by example, light the universe.

/////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////


Array Indexing Arrays Index


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

In MATLAB, each variable is an array, and the array can have many numbers. When you want to select some elements of an array, use the index value.


For example, consider the 4-by-4 magic square A:

For example, consider the following 4-row, 4-column magic Phalanx A:

A = Magic (4)

A =

16 2 3 13

5 11 10 8

9 7 6 12

4 14 15 1


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

There are two ways to access an element in an array. One of the most common is to specify the row of the element, column subscript, for example:

A (4,2)

Ans =

14

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

The other is a little bit weird, but sometimes it can be useful. This is the use of a single subscript to propose elements. (How a single subscript is used is the top to bottom of each column.) For example, this magic square, the fourth row of the first column is 4, the fourth row The second column is 8 ... )

A (8)

Ans =

14

Using a single subscript to refer to a particular element in an array is called linear indexing.

Use a single subscript to extract elements from the matrix, which is called linear indexing ...


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

On the right side of an assignment statement you refer to an element that exceeds the bounds of the array, then Matlab throws an error.

Test = A (4,5)

Attempted to access A (4,5); Index out of bounds because size (A) =[4,4].

An attempt was made to access an element of four rows and five columns; The index value exceeds the bounds because the size of a is 4 rows and 4 columns.


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

Of course, at the left of the assignment statement, you specify an element that goes beyond the bounds of the array, and assigns a number to an element that is outside the current array range. Then, the array will increase its size to accommodate the new element.


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


To refer to multiple elements of an array, with the colon operator, which allows you to specify a range of the form Start:e nd.

When you want to extract multiple elements from an array, you should use a colon:. This colon, so used, specifies the start: end this range.


For example, list the elements in the first three rows and the second column of A:

For example, some elements are presented, which are the third column elements of the first row to the third row of the array.

A (1:3,2)

Ans =

2

11

7

The colon alone, without start or end values, specifies all of the elements on that dimension.

A single colon, nor does it write where to start and where to end. Then all the elements on this dimension are specified.


For example, select all the columns in the third row of A:

For example, I want to extract all the elements of the third line of a


A (3,:)

Ans =

9 7 6) 12 0


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

Using a colon, you can also create a sequence of equal intervals. Generally speaking, the expression is written in such a 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.

If you omit the middle variable step, it's written like this start:end. Then MATLAB will use the default step variable value of 1.



/////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////


In order to let each novice use MATLAB this excellent software, so translation matlab, with the help of translation software and practice experience, may all read this translation of the people can get some enlightenment.


Because it is to help beginners to get started, so I try to people-oriented, said the novice to understand the language, not one by one translation. N (* ≧▽≦ *) n

If there is a mistake in my translation, please correct me. I will continue to improve and update the translation. Please do not hesitate to enlighten me. Be grateful.


Thanksgiving sentient beings with the use of software, PowerWord with Microsoft Word.


Note: This article is only used for scientific study. If I violate your rights, please let us know. After seeing your notice, I will promptly make a deal.

This article is original and cannot be reproduced without consent. So reprint to other sites before, please ask under.

matlab2014a Help and Reference page Chinese translation Tutorials-array indexing

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.