ignore some data in file

hi,
this is sample of data in file, what I need is ignoring the rows with marks ** in file, how do that?
1800254325 Othello (1995) 26
1800246889 Now and Then (1995) 27
1800246848 Persuasion (1995/I) 28
********Cité des enfants perdus, La (1995) 29
1800024450 Shanghai Triad (Yao a yao yao dao waipo qiao) (1995) 30
1800242776 Dangerous Minds (1995) 31
********Twelve Monkeys (1995) 32
1800026894 Wings of Courage (1995) 33
1800020413 Babe (1995) 34
1800249202 Carrington (1995) 35
thanks

2 Comments

Jan
Jan on 11 Oct 2011
Please format you text again. Start lines with a space to prevent the automatic joining of lines.
sorry the data is not appeared properly
I will give for each row digit for recognize:
1-1800254325 Othello (1995) 26
2-1800246889 Now and Then (1995) 27
3-1800246848 Persuasion (1995/I) 28
4-Cité des enfants perdus, La (1995) 29
5-1800024450 Shanghai Triad (Yao a yao yao dao waipo qiao) (1995) 30
6-1800242776 Dangerous Minds (1995) 31
7-Twelve Monkeys (1995) 32
8-1800026894 Wings of Courage (1995) 33

Sign in to comment.

Answers (2)

Kevin
Kevin on 11 Oct 2011
It isn't too elegant, but the way I would approach it is to first read in all of the text data using a text scan, something like this:
fid_format = '%s '; %USE YOUR OWN FORMAT HERE
fid = fopen(filename);
C = textscan(fid,fid_format);
fclose(fid);
Then loop over each row and do a string check and make a new "reduced" text:
string_size = size(C); for iRow = 1:string_size(1) if regexpi(char(C(iRow,1)),'*') %Do nothing else Reduced_Text{iRow,1} = char(C(iRow,1)); end end

5 Comments

thanks,
there is misunderstanding.
when I placed *** mark. I were meaning just to point it .
what I need , there are some unimportant rows because it has missing value, so it must be deleted.
such rows I indicated before.
where each row should begin with digits, so I must ignore otherwise
Kevin
Kevin on 11 Oct 2011
If you know which rows you want to exclude you can do something like this:
exclude = [1;4;10;12]; %EACH ROW YOU WANT TO EXCLUDE
count = 1;
for iRow = 1:length(text)
exclude_row = 0;
for iExclude = 1:length(exclude)
if exclude(iExclude) == iRow
exclude_row = 1;
end
end
if exclude_row == 0
new_text{count,1} = text(iRow); %REDUCED TEXT
count = count + 1;
end
end
No, I don't know because the file is very large
thanks
i want ignore each row is not beginning with digits
Kevin
Kevin on 11 Oct 2011
You should state how you are trying to differentiate the rows so we can help you a bit better up front next time.
If you open your text file with excel (WITH NO TAB DELIMIT) and save it as an excel file with NO delimiting, you can use this code to get it to work:
filename = 'SampleText.xlsx'; %Your excel file with the raw text that is not delimited
[Data Text] = xlsread(filename);
Text_Size = size(Text);
count = 1;
for iRow = 1:Text_Size(1)
tempchar = Text{iRow,1}(1); %Grab first character in cell
tempnum = str2num(tempchar); %Try to convert first character to number
if tempnum >= 0 %If str2num answer is '[]' do nothing and skip
New_Text{count,1} = Text(iRow,1);
count = count + 1;
end
end

Sign in to comment.

bym
bym on 11 Oct 2011
you can try this:
x = textscan(fid,'%f %s %f','delimiter','\t','CommentStyle','*')

3 Comments

thanks, I used it
Now, the result when I wrote x{1}, this command give NaN in place of undesired values:
x= 1.8002
NaN
1.8003
NaN
1.8000
good, I wote code to ignore each value=NaN
for i=1:length(x)
if x(i)==NaN
x(i)==[]
end
end
but it did not know what NaN.
how can solve that? if know NaN, there is no problem.an get
Also, I can get just first coloumn x{1}, how get other columns?
thanks
I try again, I got it
thank you very much.
you solved my problem. really, I'm grateful
bym
bym on 12 Oct 2011
use isnan() to find nan's. It is customary to 'accept' an answer that solved your question, so others can benefit.

Sign in to comment.

Categories

Tags

Asked:

on 11 Oct 2011

Community Treasure Hunt

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

Start Hunting!