필터 지우기
필터 지우기

How to structure input data as what I need?

조회 수: 2 (최근 30일)
reza
reza 2019년 1월 20일
편집: Stephen23 2019년 1월 21일
I have a text file with content like this:
35.921 M, 220,000, 48.509 M, 6.349 M, 54.052 M, 806,362, 41.018 M, 4.006 M, 41.564 M, 3.46 M, 40.02 M, 100,000, 39.22 M, 900,000, 36.974 M, 30,000, 36.549 M, 455,500, 35.739 M, 230,000, 33.104 M, 2.866 M, 19.627 M, 0, 18.877 M, 750,000, 19.603 M, 4.379 M, 23.982 M, 0, 10.186 M, 250,000, 10.436 M, 0, 15.414 M, 250,500, 15.465 M, 200,000, 21.571 M, 665,000, 22.236 M, 0, 15.537 M, 250,000, 15.787 M, 0, 21.422 M, 221,004, 21.243 M, 400,000, 30.662 M, 2.375 M, 33.036 M, 0, 39.287 M, 455,000, 39.742 M, 0, 53.141 M, 6.11 M, 59.131 M, 120,000, 23.587 M, 255,000, 23.842 M, 0, 17.043 M, 255,000, 17.298 M, 0, 33.51 M, 1.25 M, 34.75 M, 10,000, 36.408 M, 15,000, 28.248 M, 8.175 M, 32.367 M, 480,000, 31.535 M, 1.312 M, 54.773 M, 2.68 M, 43.936 M, 13.517 M, 58.955 M, 2.54 M, 41.234 M, 20.262 M, 45.222 M, 15,000
That I like to fill them into a N*4 dimentional matrix like this:
35.921 M, 220,000, 48.509 M, 6.349 M
54.052 M, 806,362, 41.018 M, 4.006 M
41.564 M, 3.46 M, 40.02 M, 100,000
How can I do it on Matlab?
I have attached my file to my question.
  댓글 수: 2
Stephen23
Stephen23 2019년 1월 20일
@reza: please upload the text file by clicking the paperclip button.
reza
reza 2019년 1월 20일
I have attached my file to my question.

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

채택된 답변

Stephen23
Stephen23 2019년 1월 20일
편집: Stephen23 2019년 1월 21일
str = fileread('store.txt');
str = strtrim(str);
C = regexp(str,'\s*,\s*','split');
[fid,msg] = fopen('store2.txt','wt');
assert(fid>=3,msg)
fprintf(fid,'%s, %s, %s, %s, %s\n', C{:});
fclose(fid);
EDIT: see the comments for further developments of this code.
  댓글 수: 8
reza
reza 2019년 1월 21일
Yes I know, but I liked to hear advices from an expert great programmer :)

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by