Ignore first 5 lines
Show older comments
path= 'my directory here';
[file,path] = uigetfile('*.cmn');
if isequal(file,0)
disp('User selected Cancel');
else
disp(['User selected ', fullfile(path,file)]);
end
selectedfile = fullfile(path,file);
contents=fileread(selectedfile);
Here is my code to start with, i want to ignore first 5 lines when reading the file. How can i do that?
6 Comments
Adam Danz
on 27 Apr 2021
In the future, please format your code using the [>] format button (see instructions). I've formatted it below.
path= 'my directory here';
[file,path] = uigetfile('*.cmn');
if isequal(file,0)
disp('User selected Cancel');
else
disp(['User selected ', fullfile(path,file)]);
end
selectedfile = fullfile(path,file);
contents=fileread(selectedfile);
Here is my code to start with, i want to ignore first 5 lines when reading the file. How can i do that?
Onur Esmeray
on 27 Apr 2021
Image Analyst
on 27 Apr 2021
@Onur Esmeray, I think my code below (in the official Answers section) should have worked. I assume you tried it. Why didn't it work? Or did you not even try it? If it doesn't work, attach your file with the paperclip icon so we can test it.
Adam Danz
on 27 Apr 2021
Both official answers seem feasible.
According to another answer in the forum cmn files can be read using any of the functions I listed or the approach Image Analyst mentioned. All of the functions I and Image Analyst listed allow you to specify the starting row in the file!
Read the documentation and show us what you've tried and explain why it's not working.
Onur Esmeray
on 27 Apr 2021
Edited: Onur Esmeray
on 27 Apr 2021
Image Analyst
on 28 Apr 2021
The cmn file will need to be zipped up for you to attach it because it's not one of the allowed filenames.
Accepted Answer
More Answers (1)
Adam Danz
on 27 Apr 2021
If the data is organized in rows, then you should use a file reading function designed for tabular data: readtable | readcell | readmatrix | readtimetable
T(1:5,:) = []; % removes first 5 rows of data
Categories
Find more on Resizing and Reshaping Matrices 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!