Text Data

0.0(0)
studied byStudied by 0 people
GameKnowt Play
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/14

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

15 Terms

1
New cards
  • character arrays (char data type):

    • a 1 by n character array is also known as a vector array

  • string arrays (string data type):

    • a m by n string array is also known as a string

    • a 1 by 1 string array is also known as a string scalar

  • cell arrays (cell data type)

what are the different types of text data types

2
New cards
  • enclosed by single quotes

    • e.g. message = ‘Hello’

  • each character is stored as an element in an array (above example has 5 elements)

  • can be created using the input function

    • » name = input (‘Please enter your name:’ ‘,’ ‘s’)

      → Please enter your name: (name)

      name = (name)

how do we use character vectors

3
New cards
  • char

  • num2str

  • int2str

what functions do we use to convert numeric codes into characters

4
New cards

double or +0

what function do we use to convert characters to numeric code values

5
New cards

use round brackets

how do we access elements

6
New cards

use square brackets

how do we concatenate

7
New cards
  • newStr = lower(str)

  • newStr = upper(str)

    • where str is the character vector we want to convert

    • newStr is the transformed character vector

how do we change the case of our text

8
New cards
  • use == with caution

    • generally avoid when working with character vectors

      → generates an error if character vectors aren’t the same length

      → for equal length vectors produces a logical array (not a single logical value)

      → behaves differently when using strings

comparing text data

9
New cards
  • tf = strcmp (s1, s2)

    • where s1 is a character vector

    • s2 is a character vector

    • tf is a logical value indicating whether the character vectors are identical (logical 1) or not identical (logical 0)

  • tf = strncmp (s1, s2, n)

    • where n is an integer indicating the first n characters to compare

  • tf = strncmpi (s1,s2,)

    → ignores capitalisation

strcmp

10
New cards
  • s = sprintf (format, data 1, …, data N)

    • where format is a character vector with format specifiers defining how to write the data

    • data 1, …, data N are the values or variables containing data to write out

    • s is a formatted character vector with each format specifier replaced by the formatted data

how do we format text data

11
New cards
  • s → character vector or string array

  • c → single character

  • d or i → decimal integer

  • e → scientific notation

  • f → decimal floating point

  • g → the shorter of e or f

what are the character conversions

12
New cards

\n

what character do we use to move to a new line

13
New cards
  • data = sscanf (s, format, size)

    • s is the text data to scan

    • format is a character vector detailing the data format we wish to read

    • size (optional), read enough data to fill an array with size cfInsizeA

    • data is the data extracted as a column vector

sscanf

14
New cards
  • k = strfind (str, pat)

    • str is a character vector to search in

    • pat is a character vector find in str

    • k is a numeric array that contains the starting index of each occurrence of pat in str

strfind

15
New cards
  • use double quotes

    • e.g. str_message = “Hello World”

  • contain a single string element

  • think of it as a container that holds a sequence of characters

  • you can extract the character vector from the container using curly braces {}

  • will work with the string comparison and formatting functions

string scalars