필터 지우기
필터 지우기

Is there a way to sort text file in matlab?

조회 수: 4 (최근 30일)
Matija Kosak
Matija Kosak 2018년 7월 5일
댓글: Matija Kosak 2018년 7월 5일
I have a question if there is possibility to sort through text file in matlab. I'll post 3 pictures where it says all. I have a txt file and need to make nx3 matrix from it.
-
This is first part where I have to delete first 11 rows in txt file.
-
-
Second part where I have 3 columns of numbers I need to write in matrix
-
-
Third part where I need to delete everything down from information I need to sort.
  댓글 수: 2
Stephen23
Stephen23 2018년 7월 5일
"Is there a way to sort text file in matlab?"
Yes.
Please upload a sample file. We cannot test code using screenshots of a text file.
Matija Kosak
Matija Kosak 2018년 7월 5일
Here and in main question added:)

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

채택된 답변

Stephen23
Stephen23 2018년 7월 5일
>> str = fileread('kvadrat2.txt');
>> tkn = regexp(str,'^GRID\*\s+\d+\s+(\d+,\d+)\s+(\d+,\d+)\s+\d+\s+\*\s+\d+\s+(\d+,\d+)','lineanchors','tokens');
>> tkn = vertcat(tkn{:});
>> tkn = strrep(tkn,',','.');
>> mat = str2double(tkn)
mat =
0 50.0000 0
0 50.0000 50.0000
0 0 0
0 0 50.0000
0 5.0000 0
0 10.0000 0
0 15.0000 0
0 20.0000 0
0 25.0000 0
... lots of lines here
0 20.0000 30.0000
0 25.0000 30.0000
0 30.0000 30.0000
0 30.0000 25.0000
0 30.0000 20.0000
0 25.0000 20.0000
0 25.0000 25.0000
To save the matrix in a new file use |csvwrite:
csvwrite('newfile.csv',mat)
If you really need to use a comma as the decimal radix, search this forum for "comma decimal".
  댓글 수: 5
Stephen23
Stephen23 2018년 7월 5일
@Matija Kosak: I hope that it helps. Remember to accept the answer that helped you most to resolve your question. Accepting answers is an easy way to show your appreciation of the volunteers who help you on this forum.
Matija Kosak
Matija Kosak 2018년 7월 5일
No problem, you helped me a lot.

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

추가 답변 (0개)

카테고리

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