Separate string and perform math operations in Matlab
Show older comments
Hello I have the following problem:
I have the string
num1 = '02 12 28.27'
I would like to perform operations with the numbers separately but first I need to separate the numbers, for example:
num_1 = 02
num_2 = 12
num_3 = 28.27
I was trying the following:
c = textscan(num1,'%f %f %f', 'Delimiter', ' ')
num1 = c{1}
num2 = c{2}
num3 = c{3}
I just got an empty vector.
Thanks in advance for your help!
1 Comment
Adam
on 14 Mar 2016
That is strange. If I run your code I get exactly what you are looking for. I wouldn't recommend going down the road of 3 named variables (I would use an array of num(1), num(2), num(3) instead), but that is a different matter entirely!
Accepted Answer
More Answers (0)
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!