How to remove text strings from .dat file

1 次查看(过去 30 天)
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 个评论
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 '#'?
Artyom
Artyom 2012-7-31
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
textscan(..., 'CommentStyle', '#')

类别

Help CenterFile Exchange 中查找有关 Large Files and Big Data 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by