Simple file I/O problem - help needed
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (1)
Friedrich
il 30 Dic 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 Commenti
Vedere anche
Categorie
Scopri di più su Characters and Strings in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!