Ignore first 5 lines
Ältere Kommentare anzeigen
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 Kommentare
Adam Danz
am 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
am 27 Apr. 2021
Image Analyst
am 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
am 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
am 27 Apr. 2021
Bearbeitet: Onur Esmeray
am 27 Apr. 2021
Image Analyst
am 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.
Akzeptierte Antwort
Weitere Antworten (1)
Adam Danz
am 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
Kategorien
Mehr zu Data Import and Export finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!