필터 지우기
필터 지우기

How do I identify the a specific row number in a .txt file?

조회 수: 20 (최근 30일)
Rafael Cordero
Rafael Cordero 2017년 8월 4일
답변: Rafael Cordero 2017년 8월 4일
Hello folks,
Ive got a .txt file shown above. I want to identify the row number of the circled entry (Time (s)). So, if im not mistaken, 26.
I read other similair questions and tried this:
fid = fopen('C:\wherever\textymctextface.txt', 'rt');
s = textscan(fid, '%s', 'delimiter', '\n');
loc = find(strcmp(s{1}, 'Time (s)'), 1, 'first');
So the struct s created looks fine, until the 17th row (Type Time Duration Comment). In this row, it groups the next 6 rows in that same row. So in Matlab, the variable looks like:
What gives? Why does this happen? The new row delimeter is the same throughout, and since the number of Comments is different for different files I cant just account for them.
So: how do I fix my code or does anyone have any other ideas to go about this?
Thank you!!!
R

채택된 답변

Rafael Cordero
Rafael Cordero 2017년 8월 4일
Ok solved it in a not very elegant way. I dont know why the /n wasnt being reconised in textscan but what I did was call text scan AGAIN on just that problem row and then it worked fine. I then added the row numbers and added the offset of blank rows:
fid = fopen('C:\Users\Rafa\Documents\Data\SonRMay172017Experiment\H17-1001-01_004_Subcutaneous SonR.txt', 'rt');
s = textscan(fid, '%s', 'delimiter', '\n');
ss=textscan(s{1,1}{17,1}, '%s', 'delimiter', '\n');
channel_title_row=17+length(ss{1,1})+1;
fclose(fid);

추가 답변 (1개)

fbaillon
fbaillon 2017년 8월 4일
Have you tried with the delimiters '\r\n'?
s = textscan(fid, '%s', 'delimiter', '\r\n');
  댓글 수: 1
Rafael Cordero
Rafael Cordero 2017년 8월 4일
Gives me an empty empty 1x1 cell array.
What does the '\r\n' do?

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

카테고리

Help CenterFile Exchange에서 Text Files에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by