How to remove text strings from .dat file

Hi everyone.
There is a .dat file, where the first raw of it:
#component = 1 embedding = 1
Then 20x3 matrix of numbers and again:
#component = 1 embedding = 2
So how to remove these lines from matlab when I load the file or is it better to remove from array like:
if x(1,1) == '#component';
x(1,1)=[];

댓글 수: 4

per isakson
per isakson 2012년 7월 31일
편집: per isakson 2012년 7월 31일
Something like
textscan ( ..., 'Headerlines', 1 )
This will remove only the first headline. But I need to remove all lines with
#component = 1 embedding.....
It is nearly 10 these lines in the array.
Jan
Jan 2012년 7월 31일
편집: Jan 2012년 7월 31일
x(1,1) == '#component' will most likely not do what you expect. Use STRNCMP for string comparisons.
What do you want to achieve? Do you want to modify the file or import the data ignoring all lines starting with '#'?
Oh, I solved it:
for i=1:m
if strcmp(temp.textdata{i,1},'#component');
else
x(s,:)=sscanf(sprintf('%s %s %s', temp.textdata{i,:}), '%f');
s=s+1;
end
end

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

답변 (1개)

Jan
Jan 2012년 7월 31일

0 개 추천

textscan(..., 'CommentStyle', '#')

카테고리

도움말 센터File Exchange에서 App Building에 대해 자세히 알아보기

질문:

2012년 7월 31일

Community Treasure Hunt

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

Start Hunting!

Translated by