import csv using textscan but skip lines where column value meets user criteria
1 view (last 30 days)
Show older comments
I am wanting to import a csv using textscan where rows will be skipped if a column value meets a certain criteria.
Interval,Layer,Value,Comment
1,1,-78,ok
2,2,-89,ok
3, 0,-56,want this line gone
4,4,-34,ok
I wish to
This would reat the whole lot into data. I wish to exclude the third record where Layer = 0. Can this be done as a one-liner without having to resort to line-by-line reading ?
data = textscan(fid,'%f%f%fs','Delimiter',',')
0 Comments
Answers (2)
KSSV
on 2 Jul 2019
As the data int he file are numbers..you can import/ load the data and then you can remove the unwanted numbers using inequalitites.
REad about csvread, load, importdata and ineqalitites.
2 Comments
KSSV
on 2 Jul 2019
YOu can read a file line by line as below:
fid = fopen(myfile);
tline = fgetl(fid);
while ischar(tline)
disp(tline)
tline = fgetl(fid);
end
fclose(fid);
See Also
Categories
Find more on Large Files and Big Data in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!