Textscan of a vector with spaces ("32")

1 view (last 30 days)
Hi,
I have a vector:
Msg=[ 32 52 68 32 50 69 32 51 50 32 52 32 48 32 48 ...]
Now I want to make a textscan and write all values which are separated with a space ("32") and write them into a cell array.
Info: "Msg" is only one vector from an incomming Data matrix.
Question: How can i use the syntax "textscan" for my incomming data, or is there another syntax for scanning a vector for scaces("32") and write them into a cell array?

Accepted Answer

Guillaume
Guillaume on 18 May 2015
The simplest way is probably:
c = strsplit(char(Msg), ' ')
If you want c to still contain ascii values instead of the corresponding characters:
c = cellfun(@double, strsplit(char(Msg), ' '), 'UniformOutput', false)
  4 Comments
Dennis Sattelmaier
Dennis Sattelmaier on 21 May 2015
Throug the cellfun,I have a cell with:
c= [52 68] [50 69] [51 50] [52] [48] [48]
Now I converted them into a char with:
c = cellfun(@char, strsplit(char(ReceiveMsg), ' '), 'UniformOutput', false);
c= [4D] [2E] [32] [4] [0] [0]
but I want to have the decimal of the cells:
c=[77] [46] [50] [4] [0] [0]
Guillaume
Guillaume on 21 May 2015
Note, in your example just above, the cellfun is completely unnecessary since the output of strsplit is already char.
c = strsplit(char(ReceiveMsg), ' ') %does just the same
To convert these hexadecimal values to numbers, use hex2dec:
c = hex2dec(strsplit(char(ReceiveMsg), ' '))

Sign in to comment.

More Answers (0)

Categories

Find more on Data Type Conversion in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!