How to Ignore the last line from a file read
Show older comments
Hello people,
I have the folowing file and I would like to plot it with Matlab. As you can see, the last two line are not to be print, are letters. So, how can I ignore it ? That is, I want to read and plot only the four first lines. Anyone can help with it.
1 3 10
2 6 20
3 9 30
4 12 40
END ENDe ENDe
END ENDe ENDe
Accepted Answer
More Answers (1)
JESUS DAVID ARIZA ROYETH
on 6 Dec 2019
s=readmatrix(filename);
s(any(isnan(s),2),:)=[];
figure
plot3(s(:,1),s(:,2),s(:,3),'*-r')
4 Comments
Antonio Carvalho
on 6 Dec 2019
JESUS DAVID ARIZA ROYETH
on 6 Dec 2019
Please upload your file here
Walter Roberson
on 7 Dec 2019
textscan() the file with 'headerlines', 4 and a format of '%f%f%f' . It will automatically stop reading when it encounters the text because the text does not match the numeric format.
Walter Roberson
on 7 Dec 2019
first_line = 1000;
last_line = 2000;
fmt = '%f%f%f';
fid = fopen('mech_flu.txt');
data = cell2mat( textscan(fid, fmt, last_line - first_line + 1, 'HeaderLines', first_line - 1, 'CollectOutput', true));
fclose(fid)
Categories
Find more on Text Data Preparation 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!
