Reading/Extracting data from a text file in a certain format using Matlab
이전 댓글 표시
Hi,
I am a beginner in Matlab. I need to extract some required data [ I index, J index of cells and their lengths(DX) and widths(DY)] from the attached text file in the following formate:
I J DX DY
2 2 35.53 51.93
3 2 35.53 51.93
4 2 35.53 51.93
5 2 35.53 51.93
.............................................
.............................................
196 199 35.53 51.93
197 199 35.53 51.93
댓글 수: 4
Abhilash Padma
2019년 10월 4일
what is the format of data present in text file?
Shuvashish Roy
2019년 10월 4일
Abhilash Padma
2019년 10월 4일
But data is not clear in text file. Below are the first few lines of text file. Could you explain what each line corresponds to?
2 2 963354.2231605511624366963389.7596605512080714963389.7596605512080714963354.2231605511624366
1383067.78205397375859321383067.78205397375859321383119.72205397370271381383119.7220539737027138
963371.9914105511270463 1383093.7520539737306535
35.5365000000409808 51.9399999999999977
Turlough Hughes
2019년 10월 4일
It looks like the first line corresponds to i j and the fifth to Dx Dy.
채택된 답변
추가 답변 (1개)
Turlough Hughes
2019년 10월 8일
편집: Turlough Hughes
2019년 10월 8일
No problem.
On your first question; The last index of an array can be specified by calling the index end. end + 1 means we add an additional row at the end of the arrays ij and DxDy to save the new lines read from your file. It might be helpful for you to look up matrix indexing in the documentation or the following video.
For the second question, one way is to do the following:
DMDN = ones(size(ij));
DMDN(:,1)=DMDN(:,1).*5;
DMDN(:,2)=DMDN(:,2).*3;
data = [data DMDN];
댓글 수: 3
Shuvashish Roy
2019년 10월 8일
Shuvashish Roy
2019년 10월 8일
편집: Shuvashish Roy
2019년 10월 8일
Turlough Hughes
2019년 10월 8일
Change
mod(c,5)==0
to
mod(c+1,5)==0
카테고리
도움말 센터 및 File Exchange에서 Low-Level File I/O에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!