MATLAB Answers

reza
0

How to structure input data as what I need?

reza
さんによって質問されました 2019 年 1 月 20 日
最新アクティビティ Stephen Cobeldick
さんによって 編集されました 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 件のコメント

Stephen Cobeldick
2019 年 1 月 20 日
@reza: please upload the text file by clicking the paperclip button.
reza
2019 年 1 月 20 日
I have attached my file to my question.

サインイン to comment.

1 件の回答

Stephen Cobeldick
回答者: Stephen Cobeldick
2019 年 1 月 20 日
編集済み: Stephen Cobeldick
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
2019 年 1 月 21 日
I asked because I am a machine learning student and I should learn and use Matlab everytime. But I don't need to learn javascript. So if I could repleace the above code with Matlab(web scrapping with Matlab), it would be a great job and I could be spend more time in Matlab with no need to learn javascript too!
reza
2019 年 1 月 21 日
Yes I know, but I liked to hear advices from an expert great programmer :)

サインイン to comment.



Translated by