Page 86 - Basics of MATLAB and Beyond
P. 86

subplot(221)
                               spy(A)
                               subplot(222)
                               gplot(A,[x y])
                               axis equal off
                               for i = 1:10
                                 text(x(i),y(i),int2str(i))
                               end

                               The plots show the sparse node-connection matrix on the left and the
                               physical connection on the right.

                                    Exercise 7 Repeat this communications example for the case of
                                    100 nodes around the circle. Then try changing the connection
                                    matrix. (Answer on page 187.)

                               26    Text Strings

                               A string is an array of characters.  For example, these are strings:
                               ’hello’, ’John Smith’, and ’12’. The last one is a string, not the
                               number 12, because it is surrounded by quotes. matlab represents char-
                               acters as their ascii values. You can convert between ascii values and
                               the characters they represent using the double and char commands:

                               >> alph = ’ABCDE’
                               alph  =
                               ABCDE

                               >> num = double(alph)
                               num  =
                                   65    66     67    68    69

                               >> char(num)
                               ans  =
                               ABCDE

                               >> char(num+5)
                               ans  =
                               FGHIJ
                               The double command converts its argument to double precision values,
                               the default matlab format.
                                  To get a quote character in a string use two quotes in succession:

                               >> str = ’you’’re the one’



                               c   2000 by CRC Press LLC
   81   82   83   84   85   86   87   88   89   90   91