Biomedical Engineering Reference
In-Depth Information
elements (including the rows and columns). The size of
the matrix is specified, so the elements can be computed
using for loops, followed by the references to print the
subelements. The MATLAB script is:
to as an element in a vector or as the element in the
matrix (which is logically how we would expect to refer
to it). The above script produces the following results
when executed from the command window:
>> ArrayRefs
A ¼
0.2000 0.0909 0.0345 0.0120 0.0041
0.1429 0.0769 0.0323 0.0118 0.0040
0.0909 0.0588 0.0286 0.0112 0.0040
0.0526 0.0400 0.0233 0.0103 0.0039
0.0286 0.0244 0.0169 0.0088 0.0036
ans ¼
0.2000 0.0909 0.0345 0.0120 0.0041
ans ¼
0.0909
0.0769
0.0588
0.0400
0.0244
ans ¼
0.0588
ans ¼
0.0588
% ArraysRef.m
for i ¼ 1:5
for j ¼ 1:5
A(i, j) ¼ 1/(2 ^ i þ 3 ^ j);
end
end
A
A (1,:)
A (:,2)
A (8)
A (3,2)
Notice that the first row is referred to as A (1, :). The
subscript 1 refers for the row and the second subscript is
not a number, but rather the symbol ':' which refers to all
elements in this dimension. The ':' in A (:,2) has the
same meaning, but this time it refers to the row di-
mension and means all rows with the column being fixed
at 2.
Remember that all MATLAB arrays are stored as
column vectors, with the columns following each other in
order. Therefore the element A (3, 2) can be referred
Notice that the row is displayed as a row and the column
is displayed as a column.
Search WWH ::




Custom Search