You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
8.2 Extracting Parts of Vectors>> r5 = [1:2:6, -1:-2:-7]r5 =1 3 5 -1 -3 -5 -7To get the 3rd to 6th entries:>> r5(3:6)ans =5 -1 -3 -5To get alternate entries:>> r5(1:2:7)ans =1 5 -3 -7What does r5(6:-2:1) give?See help colon for a fuller description.8.3 Column VectorsThese have similar constructs to row vectorsexcept that entries are separated by ; or “newlines”>> c = [ 1; 3; sqrt(5)]c =1.00003.00002.2361>> c2 = [345]c2 =345>> c3 = 2*c - 3*c2c3 =-7.0000-6.0000-10.5279so column vectors may be added or subtractedprovided that they have the same length.The length of a vector (number of elements)can be determined by>> length(c)ans = 3>> length(r5)ans = 7and does not distinguish between row and columnvectors (compare with size described in§15.1). The size might be needed to determinethe last element in a vector but this canbe found by using the reserved word end:>> c2(end), c2(end-1:end)ans =4ans =4 58.4 TransposingWe can convert a row vector into a column vector(and vice versa) by a process called transposingwhich is denoted by ’.>> w, w’, [1 2 3], [1 2 3]’w =1 -2 3ans =1-23ans =1.00003.00002.2361ans =1.0000 3.0000 2.2361>> t = w + 2*[1 2 3]’t =3.0000 4.0000 7.4721>> T = 5*w’-2*[1 2 3]T =3.0000-16.000010.5279If x is a complex vector, thenx’ gives the complexconjugate transpose of x:>> x = [1+3i, 2-2i]ans =1.0000 + 3.0000i 2.0000 - 2.0000i>> x’ans =1.0000 - 3.0000i2.0000 + 2.0000i6