Textscan of a vector with spaces ("32")

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

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

Thank you for the answer, works good.
Can I change the Type in this step into a decimal
I'm afraid I don't understand what you mean by Type. Can you show an example of the result you want?
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]
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

Community Treasure Hunt

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

Start Hunting!