how to delete specific raw from text file ?

I want to open this text file and delete each row from a file which starts with charachter F,D and N.after that i want to make a simple mat file with remaining data. any help will be helpful. thanks.

 채택된 답변

Ameer Hamza
Ameer Hamza 2018년 5월 15일
편집: Ameer Hamza 2018년 5월 15일

0 개 추천

You can read the file and delete these rows like this
f = fopen('04.txt');
data = textscan(f, '%s', 'Delimiter', '\n');
fclose(f);
data = data{1};
rowsToDelete = startsWith(data, {'F', 'N', 'D'});
% rowsToDelete = cellfun(@(x) any(x(1) == 'FND'), data); % for older version than R2016b
data(rowsToDelete) = [];
the variable data will contain all the remaining rows as char array. Since all these rows contain mix datatypes i.e. characters and numbers and a variable number of elements. it is not clear how do you want your final data in the numeric form.

댓글 수: 4

pruth
pruth 2018년 5월 15일
hi, thank you so much for your reply. i am using matlab 2015a. therefore i dont think the function 'startsWith' i am able to use it here. can you tell me any other way to solve this problem using matlab version 2015a ?
Ameer Hamza
Ameer Hamza 2018년 5월 15일
please see the updated code.
pruth
pruth 2018년 5월 15일
that works perfectly. thank you so much. :)
Ameer Hamza
Ameer Hamza 2018년 5월 15일
you are welcome.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Data Import and Export에 대해 자세히 알아보기

질문:

2018년 5월 15일

댓글:

2018년 5월 15일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by