How to extract number from what should be a string

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

 Accepted Answer

Can you use char()?
textdata = {{'teststring'}};
class(textdata{1})
% but
output = char(textdata{1});
class(output), output

1 Comment

Yes, that works gr8 ;D
Thanks a lot!
Rasmus Kirkegaard

Sign in to comment.

More Answers (1)

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.

Community Treasure Hunt

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

Start Hunting!