MATLAB: How to split a string into two strings using a space + number delimiter and/or search for the delimiter by counting right to left

MATLABregexpstringstrsplit

Hello,
I have data entries that look like this:
Column 1 | Column 2
Default | 8
Default 2 | 9
Default 3 | 3
Default 4 | 5
Card 1 | 6
Card 1 2 | 10
Card 1 3 | 3
Card 1 4 | 2
Card 1 5 | 9
Card 1 6 | 3
Card 2 | 2
Card 2 2 | 2
Card 2 3 | 6
Card 2 4 | 8
Card 2 5 | 6
Card 2 6 | 9
I want to be able to split all the column 1 entries into two columns, the base part and the number. The number I'm interested in is ONLY the last number after the last space. The base part is allowed to have a number in it.
The only common thing between all the entries is that they end with [space][number] and number can be between 1 and 10000.
For the entries similar to the (1,1) entry above, I need to get a 0 at the end of that string as well.
I think I can use 'strsplit' or 'regexp' to do this, but I'm not sure how to tell Matlab that I need it to split at the end of the string effectively (have it count in from the right).
Thanks for any assistance you are able to give,
Matt

Best Answer

Not sure what exactly the format of your data is (use valid matlab syntax to construct your examples to avoid ambiguity). Is column 2 relevant here? Also, not sure what "For the entries similar to the (1,1) entry above, I need to get a 0 at the end of that string as well." mean.
To split a char vector 'Card 2 6' or similar into {'Card 2', '6'}:
str = 'Card 2 6';
split = regexp(str, '(.*?) (\d+)$', 'tokens')
This basically creates two tokens, the 2nd token must be preceded by a space, must consist of digits and attached to the end of the input (because of the $. The first token is everything else before the space.