Ignore first 5 lines
Afficher commentaires plus anciens
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 commentaires
Adam Danz
le 27 Avr 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
le 27 Avr 2021
Image Analyst
le 27 Avr 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
le 27 Avr 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
le 27 Avr 2021
Modifié(e) : Onur Esmeray
le 27 Avr 2021
Image Analyst
le 28 Avr 2021
The cmn file will need to be zipped up for you to attach it because it's not one of the allowed filenames.
Réponse acceptée
Plus de réponses (1)
Adam Danz
le 27 Avr 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
Catégories
En savoir plus sur Resizing and Reshaping Matrices dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!