フィルターのクリア

refrencing elements kindly explain each one

8 ビュー (過去 30 日間)
HAMID ALI SHAH
HAMID ALI SHAH 2019 年 3 月 1 日
コメント済み: HAMID ALI SHAH 2019 年 3 月 2 日
please kindly explain each one i am not understanding whats happening in this so please kindly help me i am very beginner in matlab
  1 件のコメント
Guillaume
Guillaume 2019 年 3 月 1 日
Have you read the Getting Started tutorial in the documentation? Particularly, the 3rd topic Array Indexing.
Or any other introduction tutorial to matlab. What you're asking is really really basic and be covered in countless tutorials.

サインインしてコメントする。

採用された回答

Bob Thompson
Bob Thompson 2019 年 3 月 1 日
1) The first and second statements are really just the same thing, which is defining contents of matrices A and b. We know they are defining values because an = sign is being used between the variable (A) and the square brackets. Spaces, or commas, are used to indicate a new column, and semicolons, ;, are used to indicate a new row. Matrices are required to be rectangular, so each row must have the same number of columns.
2) As a bit of side note, square brackets, [], are used to indicate a concatenation, or a grouping of values. This can be used when defining variables, as seen in the first two statements, or when referencing a variable's contents, as shown in the fifth statement. More on that later.
3) Now that we have defined our variable contents we want to use specific values. To do so we need to specify their location within the array. This process is called reference, or indexing, and the location is often called an index. Referencing a value, called an element, within a numeric array is rather simple, you just need to name the variable and then follow it with the element index in parentheses. The third statement does this, calling variable A, and then specifying (2,3) for the element. The order of the index of the element is (row, column, sheet, 4th, 5th, etc.). An array within MATLAB can have an 'infinite' number of dimensions, but I won't name them specifically because they quickly lose visual representatives.
4) If your array only has one dimension that is not equal in size to 1, then you only need to specify the index in the non-one direction. The fourth statement shows this. b has a size of 3x1, so calling the first element of the second row would techinically be accomplished with b(2,1), but because b only has one direction that is not a size of 1, then you can shorten the reference to b(2). If b had a size of 1x3, this same principle would apply and you could still call the middle element of b with b(2).
5) It is possible to specify more than one element in an index. As mentioned earlier, the use of square brackets allows for the grouping of values. These values can be called individually in this manner, and do not need to be consecutive. The fifth statement is an example of this.
6) If you wanted to call a range of values, specifying each one could become rather tedious. To simplify this you can use the colon, :, within the index calling to specify all values between a first and a last number. Statement six is an example of this, where variable A is called, and a range is specified for all rows between and including rows 1 and 2, and all columns between and including columns 2 and 3. It is not necessary to specify a range in all directions, if only a single row, column, sheet, etc, is applicable. Statement seven is an example of this.
7) There are some words that can be called while indexing instead of specific numbers. Using 'end' in an index reference will indicate that you want the largest index possible in a specific direction. For A, whose size is 3x3, calling 'end' will give 3 for either rows or columns, whichever is specified. It is not necessary to specify these values within a range. The seventh statement is also an example of this.
8) It is possible to do 'math' within an index reference. If you want all elements in a certain direction, except the last one, you can specify a range 1:end-1. By defining the beginning of the range as 1, you have said you want to start at the beginning of the dimension, and specifying the end of the range as 'end-1' you have said you want to step back one value from the final set of values in that direction. To give a numeric representative of this, if you have A(1:end-1,1) you will get A(1:(3-1),1) == A(1:2,1). Statement eight is another example of this.
For an additional reference on indexing see this.
  1 件のコメント
HAMID ALI SHAH
HAMID ALI SHAH 2019 年 3 月 2 日
THANK YOU SIR! IT HELPS ALOT

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by