Simple file I/O problem - help needed

1 vue (au cours des 30 derniers jours)
Chris
Chris le 30 Déc 2011
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

Réponses (1)

Friedrich
Friedrich le 30 Déc 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

Catégories

En savoir plus sur Characters and Strings dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by