Table 5-2: MATLAB/C Indexing Expression Equivalence
Description
|
MATLAB Expression
|
C Expression
|
Result
|
Extract 1,1 element
|
X(1,1)
|
mlfIndexRef(
X,
"(?,?)",
mlfScalar(1),
mlfScalar(1)
)
|
4
|
Extract first element
|
X(1)
|
mlfIndexRef(
X,
"(?)",
mlfScalar(1)
)
|
4
|
Extract third element
|
X(3)
|
mlfIndexRef(
X,
"(?)",
mlfScalar(3)
)
|
5
|
Extract all elements into column vector
|
X(:)
|
mlfIndexRef(
X,
"(?)",
mlfCreateColonIndex()
)
|
4
6
5
7
|
Extract first row
|
X(1,:)
|
mlfIndexRef(
X,
"(?,?)",
mlfScalar(1),
mlfCreateColonIndex()
)
|
4 5
|
Extract second row
|
X(2,:)
|
mlfIndexRef(
X,
"(?,?)",
mlfScalar(2),
mlfCreateColonIndex()
)
|
6 7
|
Extract first column
|
X(:,1)
|
mlfIndexRef(
X,
"(?,?)",
mlfCreateColonIndex(),
mlfScalar(1)
)
|
4
6
|
Extract second column
|
X(:,2)
|
mlfIndexRef(
X,
"(?,?)",
mlfCreateColonIndex(),
mlfScalar(2)
)
|
5
7
|
Replace first element with 9
|
X(1) = 9
|
mlfIndexAssign(
&X,
"(?)",
mlfScalar(1),
mlfScalar(9)
);
|
9 5
6 7
|
Replace first row with
[11 12]
|
X(1,:) = [ 11 12 ]
|
mlfIndexAssign(
&X,
"(?,?)",
mlfScalar(1),
mlfCreateColonIndex(),
mlfHorzcat(
mlfScalar(11),
mlfScalar(12),
NULL)
);
|
11 12
6 7
|
Replace element 2,1 with 9
|
X(2,1) = 9
|
mlfIndexAssign(
&X,
"(?,?)",
mlfScalar(2),
mlfScalar(1),
mlfScalar(9)
);
|
4 5
9 7
|
Replace elements 1 and 4 with 8 (one-dimensional indexing)
|
X([1 4]) = [ 8 8 ]
|
mlfIndexAssign(
&X,
"(?)",
mlfHorzcat(
mlfScalar(1),
mlfScalar(4),
NULL),
mlfHorzcat(
mlfScalar(8),
mlfScalar(8),
NULL)
);
|
8 5
6 8
|