Simple file I/O problem - help needed
조회 수: 1 (최근 30일)
이전 댓글 표시
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
답변 (1개)
Friedrich
2011년 12월 30일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Characters and Strings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!