Ignore first 5 lines
이전 댓글 표시
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
Adam Danz
2021년 4월 27일
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
2021년 4월 27일
Image Analyst
2021년 4월 27일
@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
2021년 4월 27일
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
2021년 4월 27일
편집: Onur Esmeray
2021년 4월 27일
Image Analyst
2021년 4월 28일
The cmn file will need to be zipped up for you to attach it because it's not one of the allowed filenames.
채택된 답변
추가 답변 (1개)
Adam Danz
2021년 4월 27일
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
카테고리
도움말 센터 및 File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!