Alex Rivera | Logout

extract first 4 letters from a string in matlab

Asked 2011-04-04T22:33:07.010
10

How can I extract the first 4 or the middle 4 or last four letters of a string example: when the string reads 01 ED 01 F9 81 C6?

Edit
Report

1 Answer

0

As trolle3000 and b3 mentioned, you use brackets containing indices to extract subsets of the string.

To answer the additional question of how you work on the string, I suggest that you split the string at each space, and convert from hexadecimal to decimal numbers.

s = '01 ED 01 F9 81 C6';
hex2dec(regexp(s, ' ', 'split'))

ans =   
     1
   237
     1
   249
   129
   198
answered 2011-04-05T10:56:21.757

Your Answer