How to read one number from multiple text files

조회 수: 1 (최근 30일)
Maha Almarzooqi
Maha Almarzooqi 2020년 3월 17일
댓글: Maha Almarzooqi 2020년 3월 30일
Hello,
I have been struggeling with finding a way to read 1000 text files into matlab. The text files have letters in them as well, however from every text file I only want one number. I have tried dlmread, that doesnt work. I Have tried fopen, I couldnt figure out how can I specifiy the numer location (which row and couloumn).
I would very much appreciate it if someone knows a way!!
  댓글 수: 5
Maha Almarzooqi
Maha Almarzooqi 2020년 3월 18일
row 5 couloumn 6 --> -7.89296...
dpb
dpb 2020년 3월 18일
That's a trivial file format to read presuming that is the beginning of the file...
data=readmatrix('Yourfilename.txt','NumHeaderLines',1,'Range','E6');
the overhead of the specific element read may/may not be significant; the previous suggestion would have just been
data=readmatrix('Yourfilename.txt','NumHeaderLines',1); % read full data array
data=data(5,6); % keep the wanted data

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

채택된 답변

Sindhu Karri
Sindhu Karri 2020년 3월 23일
This is an alternate solution
fileID = fopen('textfile.txt','r');%textfile to be included in the current folder path
formatSpec = '%d %d %d %d';
sizeA = [4 6];%dimensions of the data to be read
A = fscanf(fileID,formatSpec,sizeA);
A=A'
b=A(6,3)% to get the specified number
fclose(fileID);
Refer to below link
  댓글 수: 2
Walter Roberson
Walter Roberson 2020년 3월 23일
You need an initial fgets(fileID) to skip the header line.
What is the reasoning for bothering to take the transpose? Why not omit it and use A(3,6) ?
Maha Almarzooqi
Maha Almarzooqi 2020년 3월 30일
Thank you for your answers dpb and sindhu. I also agree with Walter regarding the concern on why the transpose?

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by