12.07.2015 Views

Basics of MATLAB and Beyond

Basics of MATLAB and Beyond

Basics of MATLAB and Beyond

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

subplot(221)spy(A)subplot(222)gplot(A,[x y])axis equal <strong>of</strong>ffor i = 1:10text(x(i),y(i),int2str(i))endThe plots show the sparse node-connection matrix on the left <strong>and</strong> thephysical connection on the right.Exercise 7 Repeat this communications example for the case <strong>of</strong>100 nodes around the circle. Then try changing the connectionmatrix. (Answer on page 187.)26 Text StringsA string is an array <strong>of</strong> characters. For example, these are strings:’hello’, ’John Smith’, <strong>and</strong> ’12’. The last one is a string, not thenumber 12, because it is surrounded by quotes. matlab represents charactersas their ascii values. You can convert between ascii values <strong>and</strong>the characters they represent using the double <strong>and</strong> char comm<strong>and</strong>s:>> alph = ’ABCDE’alph =ABCDE>> num = double(alph)num =65 66 67 68 69>> char(num)ans =ABCDE>> char(num+5)ans =FGHIJThe double comm<strong>and</strong> 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

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!