Separate numerical and txt string into two different strings
Show older comments
Hello people
I have a string M_b = '1000 km' and I want to separated to M_b1 = 1000 (a numerical string) and to M_b2 = km (a text string).
To tell the truth only M_b1 is of importance for me. But the data comes from an excel and by using xlsread I can only transfer the data to matlab as txt.
I tried multiple things without any success like: M_b1 = str2num('M_b') [M_1b,M_2b] = strread('M_b', %s) [M_1b,M_2b] = strread (sprintf('M_b'), %s) M_b1 = textscan(M_b,'%s')
I am new to matlab but I can learn fast Thank you for your time
Accepted Answer
More Answers (2)
Fangjun Jiang
on 16 Nov 2011
You are close.
M_b = '1000 km';
M_b1 = textscan(M_b,'%f')
Categories
Find more on Characters and Strings 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!