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.

str =you’re the one>> str = ’’’you’’re the one’’’str =’you’re the one’Exercise 8 Create a table <strong>of</strong> integers from 0 to 255 <strong>and</strong> theirequivalent ascii values. Printing which ascii “character” ringsthe system bell? (Answer on page 187.)26.1 String MatricesTo create a matrix <strong>of</strong> strings, use the semicolon to separate the lines:>> m = [alph ; char(num+5) ; ’KLMNO’]m =ABCDEFGHIJKLMNOYou cannot create a matrix <strong>of</strong> strings having different lengths:>> z = [alph ; ’b’]??? All rows in the bracketed expression must have thesame number <strong>of</strong> columns.(You should use cell arrays—discussed later—if you really want to createa “matrix” like this.) To simulate the effect, though, you can pad withzeros:>> z = [’abcd’ ; ’b ’]z =abcdbThe second line has three blank spaces to the right <strong>of</strong> the “b”. A convenientway to do this is to use the char function, which does the paddingfor you:>> z = char(’These’,’lines are’,’<strong>of</strong> varying lengths.’)z =Theselines are<strong>of</strong> varying lengths.c○ 2000 by CRC Press LLC

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

Saved successfully!

Ooh no, something went wrong!