Programming Fundamentals - The MathWorks - #50

/ 840


catalogue search
P. 01
P. 02
P. 03
P. 04
P. 05
P. 06
P. 07
P. 08
P. 09
P. 10
P. 11
P. 12
P. 13
P. 14
P. 15
P. 16
P. 17
P. 18
P. 19
P. 20
P. 21
P. 22
P. 23
P. 24
P. 25
P. 26
P. 27
P. 28
P. 29
P. 30
P. 31
P. 32
P. 33
P. 34
P. 35
P. 36
P. 37
P. 38
P. 39
P. 40
P. 41
P. 42
P. 43
P. 44
P. 45
P. 46
P. 47
P. 48
P. 49
P. 50


See other catalogues for The MathWorks

Text version of the page
1 Matrices and Arrays
7 8
Single-Colon Indexing with Different Array Types
When you index into a standard MATLAB array using a single colon, MATLAB returns a column vector (see variable n, below). When you index into a structure or cell array using a single colon, you get a comma-separated list "Comma-Separated Lists" on page 3-83 (see variables c and s,below).
Create three types of arrays:
n= [12 3; 4 5 6]; c = {1 2; 3 4};
s = cell2struct(c, {'a', 'b'}, 1); s(:,2)=s(:,1); Use single-colon indexing on each:
ans = ans = ans =
11 1
4ans=ans=
2 3 2 5ans=ans=
3 2 1 6ans=ans=
42
Indexing on Assignment
When assigning values from one matrix to another matrix, you can use any of the styles of indexing covered in this section. Matrix assignment statements also have the following requirement.
In the assignment A(J,K,...) = B(M,N,...), subscripts J, K, M, N,etc. may be scalar, vector, or array, provided that all of the following are true:
• The number of subscripts specified for B, not including trailing subscripts equal to 1, does not exceed ndims(B).
• The number of nonscalar subscripts specified for A equals the number of nonscalar subscripts specified for B.For example, A(5,1:4,1,2)
1-26

pageCatalog pdf di En 2012-06-22-01