Read .dat file in matlab

I have a .dat mesh file which looks something like this
v 0 1 2 3
v 2 4 5
..
Any idea how I can read the file in matlab and find the number of occurrences of a particular string and also the number of integers in a particular row?

댓글 수: 1

Sandeep
Sandeep 2013년 2월 4일
Suppose, I want to extract a certain data by arranging the entire data in the file in an array provided each row has different number of data like
v 1 2 3 4 6
v 1 2 0
v 3 4 9 2..
Also, is there any way to find the number of numbers in each row?

댓글을 달려면 로그인하십시오.

답변 (1개)

Image Analyst
Image Analyst 2013년 2월 3일
편집: Image Analyst 2013년 2월 3일

0 개 추천

Just read it in line by line with fgetl(). Then use strfind() on each line to see if some sequence of numbers you're interested in exists in the string.
fid = fopen('sandeep data.dat);
tline = fgetl(fid);
while ischar(tline)
disp(tline)
tline = fgetl(fid);
if strfind(s, '2 4 5') > 0
message = 'Found it';
uiwait(msgbox(message));
end

댓글 수: 2

Sandeep
Sandeep 2013년 2월 4일
Thanks.. I have another question.. Suppose, I want to extract a certain data by arranging the entire data in the file in an array provided each row has different number of data like
v 1 2 3 4 6
v 1 2 0
v 3 4 9 2..
Also, is there any way to find the number of numbers in each row?
Just count the spaces. The number of spaces equals the number of numbers:
numberOfNumbers = sum(s == ' ')

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Large Files and Big Data에 대해 자세히 알아보기

질문:

2013년 2월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by