Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 170 – INTRO TO SCIENTIFIC AND ENGINEERING PROGRAMMING.

Similar presentations


Presentation on theme: "CS 170 – INTRO TO SCIENTIFIC AND ENGINEERING PROGRAMMING."— Presentation transcript:

1 CS 170 – INTRO TO SCIENTIFIC AND ENGINEERING PROGRAMMING

2 Character Arrays Numeric arrays ~ double arrays ~ matrices Character array or char or strings Use the single quote ’ to create basic character arrays Example >> A = ’Dr. X is the teacher’; >> size(A) >> class(A) >> whos

3 Character Arrays How much memory does a character array use? Example: Recall that a double array uses 8 bytes/element >> B = rand(1,19); >> A = ’Dr. X is the teacher’; >> size(A) >> size(B) >> whos So, character arrays only use 2 bytes/element.

4 Numeric Values of Character Arrays A character array = numberic array = integer values You can convert a character array into its numeric array using the command DOUBLE. You can convert a double array with integer values into its equivalent character array using the CHAR command. >> double([’Class is half over’]) >> v=[98 101 32 112 97 116 105 101 110 116] >> char(v)

5 Referencing a CHAR array Use integer indices Example >> A = ’Dr. X is the teacher’; >> A(1:4) >> A(end:-1:1) >> A([5 8 12])

6 Concatenating CHAR arrays Use square brackets to stack Example >> str1 = ’Math is fun, ’; >> str2 = ’but Engineering is better!’; >> str3 = [str1 str2] >> size(str1) >> size(str2) >> size(str3) >> str4 = [str1 ; ’ ’ str2]; >> disp(str4)

7 QUESTIONS??


Download ppt "CS 170 – INTRO TO SCIENTIFIC AND ENGINEERING PROGRAMMING."

Similar presentations


Ads by Google