Simple file I/O problem - help needed
1 view (last 30 days)
Show older comments
I have imported a file in this format:
"title1", "title2"
"somestring1", "5423423"
"somestring2", "091843"
(without the white spaces shown here)
I need to read this file and get the number. I can do this very simply in a simple programming language but I have trouble in Matlab.
All I can think of is make a function like this:
function [ ] = getN( file )
f = fscanf(file);
%Find and get the number between the 3rd and 4th " with a check like if fscanf(file, '%c') is " do that
end
Yes I am beginner, I don't even know how to print :P
0 Comments
Answers (1)
Friedrich
on 30 Dec 2011
Hi,
I created a test file (test.txt) with the following content:
"title1","title2"
"somestring1","5423423"
"somestring2","091843"
And in MATLAB I used:
fid = fopen('test.txt','r');
data = textscan(fid,'%*s %*c %f %*c','delimiter',',','headerlines',1);
fclose(fid);
numeric_val = data{1}
numeric_val =
5423423
91843
0 Comments
See Also
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!