Main Content

extractNMEASentence

Verify and extract NMEA sentence data into string array

Since R2021b

Description

[isValid,splitString] = extractNMEASentence(unparsedData,'MessageID') verifies the checksum of an unparsed NMEA sentence, identified using its Message ID, and extracts the NMEA fields from NMEA sentence data into a string array, splitString.

example

Examples

collapse all

Provide unparsed GGA, GSA, and RMC sentences as the input.

unparsedGGALine = '$GPGGA,111357.771,5231.364,N,01324.240,E,1,12,1.0,0.0,M,0.0,M,,*69';
unparsedGSALine = '$GPGSA,A,3,01,02,03,04,05,06,07,08,09,10,11,12,1.0,1.0,1.0*30';
unparsedRMCLine = '$GPRMC,111357.771,A,5231.364,N,01324.240,E,10903,221.5,020620,000.0,W*44';

Create a string array to include the three sentences

unparsedNMEAData = [unparsedGGALine,newline,unparsedGSALine,newline,unparsedRMCLine]
unparsedNMEAData = 
    '$GPGGA,111357.771,5231.364,N,01324.240,E,1,12,1.0,0.0,M,0.0,M,,*69
     $GPGSA,A,3,01,02,03,04,05,06,07,08,09,10,11,12,1.0,1.0,1.0*30
     $GPRMC,111357.771,A,5231.364,N,01324.240,E,10903,221.5,020620,000.0,W*44'

Specify GSA as the Message ID to extract the NMEA fields from the NMEA sentence into string array.

[isValid, splitString] = extractNMEASentence(unparsedNMEAData,'GSA')
isValid = logical
   1

splitString = 1x19 string
    "GP"    "GSA"    "A"    "3"    "01"    "02"    "03"    "04"    "05"    "06"    "07"    "08"    "09"    "10"    "11"    "12"    "1.0"    "1.0"    "1.0"

Input Arguments

collapse all

The unparsed NMEA data as obtained from the device.

The Message ID to identify the unparsed NMEA sentence.

Output Arguments

collapse all

Determine the validity of unparsed NMEA sentence based on checksum. A value of 1 indicates that the checksum is valid. A value of 0 indicates that the checksum is invalid; however, the fields of NMEA sentence appear in the splitString output if the specified MessageID is matching.

Data Types: logical

Output data as split strings based on the structure that you defined. If the specified MessageID is not found in the NMEA sentence, the function returns an empty splitString.

Data Types: string

Version History

Introduced in R2021b

See Also

Objects