How to extract number from what should be a string
3 views (last 30 days)
Show older comments
Hey
I sure hope someone can help me. I could not find any solutions to my problem in the forum questions.
I am trying to extract a number from "textdata(1,1)" that I thought contained a string, but seems to contain a "cell". Is there any solution to get the number?
Thanks in advance
Rasmus Kirkegaard
>> textdata(1,1)
ans =
'#Binsizes 2000000'
>> s = '#Binsizes 2000000';
>> A = sscanf(s,'%*s %f')
A =
2000000
>> A = sscanf(textdata(1,1),'%*s %f')
Error using sscanf
First argument must be a string.
>> class(textdata(1,1))
ans =
cell
0 Comments
Accepted Answer
Wayne King
on 21 Nov 2011
Can you use char()?
textdata = {{'teststring'}};
class(textdata{1})
% but
output = char(textdata{1});
class(output), output
More Answers (1)
the cyclist
on 21 Nov 2011
I think you just need to use:
>> A = sscanf(textdata{1,1},'%*s %f')
Notice the curly brackets instead of parentheses. This way, you will access the contents of the cell, rather than the cell itself.
0 Comments
See Also
Categories
Find more on Pie Charts 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!